Re: Pattern synonym 'Required' constraints === Datatype Contexts(?)
Richard Eisenberg <[email protected]> Fri, 12 Mar 2021 18:30:49 +0000
| Newsgroups | gmane.comp.lang.haskell.glasgow.user |
|---|---|
| Message-ID | <010f017827b4970d-c969ad6a-88d8-4f5b-abb0-2399be82d86e-000000@us-east-2.amazonses.com> |
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 <[email protected]> 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@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 > [email protected] > http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users _______________________________________________ Glasgow-haskell-users mailing list [email protected] http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users