[Haskell-cafe] RebindableSyntax, ifThenElse, and pattern matching

Richard Eisenberg eir at cis.upenn.edu
Mon Feb 8 03:06:54 UTC 2016


If you have a use-case that requires an expansion of RebindableSyntax, please post a feature request. There is a very limited number of person-hours devoted to improving GHC, so we need concrete direction from users.

That said, RebindableSyntax has gotten quite a face-lift for 8.0, mostly internally. But it means that some types are more flexible than they were. However, neither problem in this thread is addressed by the changes.

But to the email below: I'm not sure how we would support anything but Bool. According to the Report,

> f "r" = "rrr"

becomes

> f x | x == "r" = "rrr"

Because the result of == is used as a guard, it would have to be a Bool. I'd be all for a new -XOverloadedBooleans, but that's still separate from RebindableSyntax.

The enumFromTo bit would be easy to fix, though. If you want it for practical purposes (that is, not just because its omission is aesthetically suboptimal -- which it is), please post a feature request.

Richard

On Feb 7, 2016, at 3:00 PM, Adam Bergmark <adam at bergmark.nl> wrote:

> There are a number of things one might expect RebindableSyntax to support, but it doesn't. Another examples is that `[1..2]' uses `GHC.Enum.enumFromTo' instead of the `enumFromTo' in scope.
> 
> My guess is that RebindableSyntax isn't on the priority list.
> 
> - Adam
> 
> 
> 
> On Sun, Feb 7, 2016 at 8:08 PM, Chris Smith <cdsmith at gmail.com> wrote:
> In a custom prelude, I have written the following definitions:
> 
> data Truth = True | False
> 
> ifThenElse :: Truth -> a -> a -> a
> ifThenElse True x _ = x
> ifThenElse False _ x = x
> 
> (==) :: a -> a -> Truth
> (==) = ...
> 
> I'm replacing Bool with my own Truth type.  Clients will be built with RebindableSyntax, so that they will use these definitions for desugaring.
> 
> However, if I write this:
> 
> f :: Text -> Text
> f "r" = "rrr"
> f other = other
> 
> I get a build error indicating that GHC expected the (==) operator to return a value of type Bool, rather than Truth.
> 
> Shouldn't pattern matching desugar to use overloaded ifThenElse in these situations?  Or is it expected that use of GHC.Types.Bool is hard-coded even with RebindableSyntax enabled?
> 
> Thanks,
> Chris
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> 
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160207/15ca87b4/attachment.html>


More information about the Haskell-Cafe mailing list