Pattern synonym type flexibility

Carter Schonwald carter.schonwald at gmail.com
Wed Apr 20 17:27:08 UTC 2016


Would that duality be related to the given vs wanted constraints ?

On Wednesday, April 20, 2016, David Feuer <david.feuer at gmail.com> wrote:

> As far as I can tell from the 7.10 documentation, it's impossible to
> make a bidirectional pattern synonym used as a constructor have a
> different type signature than when used as a pattern. Has this been
> improved in 8.0? I really want something like
>
> class FastCons x xs | xs -> x where
>   fcons :: x -> xs -> xs
> class FastViewL x xs | xs -> x where
>   fviewl :: xs -> ViewL x xs
>
> pattern x :<| xs <- (fviewl -> ConsL x xs) where
>   x :<| xs = fcons x xs
>
> This would allow users to learn just *one* name, :<|, that they can
> use for sequences that are consable or viewable even if they may not
> be the other.
>
> If this is not yet possible, then I think the most intuitive approach
> is to sever the notions of "pattern synonym" and "smart constructor".
> So I'd write
>
> pattern x :<| xs <- (fviewl -> ConsL x xs)
> constructor (:<|) = fcons
>
> The current syntax could easily be desugared to produce *both* a
> pattern synonym and a smart constructor in the bidirectional case.
> _______________________________________________
> ghc-devs mailing list
> ghc-devs at haskell.org <javascript:;>
> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20160420/feefe886/attachment.html>


More information about the ghc-devs mailing list