Pattern synonym 'Required' constraints === Datatype Contexts(?)

Anthony Clayden anthony_clayden at clear.net.nz
Fri Mar 12 11:37:57 UTC 2021


Thank you Richard, Lennart, *Gergő*

>* pattern Positive :: (Ord a, Num a) => a*

>* pattern Positive <- ((>0) -> True)*


*Heh heh, there's another surprise/undocumented 'feature'.*

*It's not necessary to give a signature for pattern `Positive`, GHC
will infer that from the decl.*

*I was surprised to see `True`, and even more surprised there wasn't a
`Bool` in the signature.  I guess that's so `Positive` can appear as a
pattern in a case expr. To dig out the positive value in a lambda
expr, it seems I go*


*> (\p at Positive -> p) 5         -- returns 5*


*Seems I can't use any trick like that to turn `Positive` into
explicitly bidirectional. I also tried*


>* pattern Positive' <- ((>0) -> ())*


*But that's rejected  '"** Couldn't match expected type `Bool' with
actual type `()'".

Is the hidden `Bool` documented somewhere? (Doesn't seem to be in the
User Guide nor the wiki nor the paper, on a quick scan.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/glasgow-haskell-users/attachments/20210313/469e7c70/attachment.html>


More information about the Glasgow-haskell-users mailing list