Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does `~` mean in Haskell?

Tags:

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?

like image 228
Roman Gonzalez Avatar asked Feb 15 '10 01:02

Roman Gonzalez


1 Answers

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.

like image 141
Michael Easter Avatar answered Sep 20 '22 14:09

Michael Easter