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

Richard Eisenberg rae at richarde.dev
Fri Mar 12 18:30:49 UTC 2021


No hidden Bool here -- this is just a consequence of the way that view patterns work, where you have to match against the result of the function, in this case, (>0). See https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/exts/view_patterns.html

Richard

> On Mar 12, 2021, at 6:37 AM, Anthony Clayden <anthony_clayden at clear.net.nz> wrote:
> 
> 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.)
> 
> 
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/glasgow-haskell-users/attachments/20210312/51ce1ca1/attachment.html>


More information about the Glasgow-haskell-users mailing list