I'm studying the mtl
library and trying to do some MonadTransformers of my own. I was checking the Control.Monad.State.StateT
declaration, and across all the code, I see this syntax:
execStateT :: (Monad m) => StateT s m a -> s -> m s execStateT m s = do ~(_, s') <- runStateT m s return s'
What does this ~
operand mean?
This is the notation for a lazy pattern in Haskell. I can't say that I'm familiar with it but from here:
It is called a lazy pattern, and has the form ~pat. Lazy patterns are irrefutable: matching a value v against ~pat always succeeds, regardless of pat. Operationally speaking, if an identifier in pat is later "used" on the right-hand-side, it will be bound to that portion of the value that would result if v were to successfully match pat, and ⊥ otherwise.
Also, this section may be useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With