[Haskell-cafe] nice simple problem for someone struggling....

David Menendez dave at zednenem.com
Fri Dec 21 15:57:00 EST 2007


On Dec 21, 2007 2:38 PM, Jules Bean <jules at jellybean.co.uk> wrote:

> David Menendez wrote:
> >> That's a reasonable thing to assume. It just happens that Haskell
> > doesn't work that way. There's an asymmetry between constructing and
> > pattern-matching, and it's one that many people have complained about.
>
> With GADTs turned on (-XGADTS in 6.8, -fglasgow-exts in 6.6) pattern
> matchings will give rise to class contexts as you would naively expect.
>
> Contexts on constructors aren't actualy haskell98, it is a bug that GHC
> 6.6 accepts them without any extensions being activated. Or that's my
> understanding, see http://hackage.haskell.org/trac/ghc/ticket/1901


I think I saw [1] and just mentally substituted [2]. In fact, until just now
I didn't know [1] was even possible. (Wasn't there some problem with class
contexts in GADTs?)

[1] data SquareType a = (Num a) => SquareConstructor a
[2] data (Num a) => SquareType a = SquareConstructor a

Okay, so pattern-matching in case [1] does guarantee Num a. In that case,
the original code didn't work because it was trying to unify Int with an
arbitrary instance of Num.

-- 
Dave Menendez <dave at zednenem.com>
<http://www.eyrie.org/~zednenem/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20071221/b7661ade/attachment.htm


More information about the Haskell-Cafe mailing list