[Haskell-cafe] GADT and instance deriving

Alexander Solla alex.solla at gmail.com
Sat May 25 00:06:50 CEST 2013


On Fri, May 24, 2013 at 10:41 AM, Niklas Hambüchen <mail at nh2.me> wrote:

> On Sat 25 May 2013 00:37:59 SGT, TP wrote:
> > Is this the right way to go? Is there any other solution?
>
> I believe whether it's right or just depends on what you want to express.
>
> > Do you confirm that tilde in s~s1 means "s has the same type as s1"?
>
> It means: Both your s and s1 are "Eq"s but not necessarily the same one.
>
>
No, it doesn't.  s1 ~ s2 means the types are the same.  ~ is the "equality
constraint".

http://www.haskell.org/ghc/docs/7.4.1/html/users_guide/equality-constraints.html

To say that s1 and s2 are Eq's, but not necessarily the same one, we would
write a constraint of the form:

(Eq s1, Eq s2) =>

That is a completely different notion of equality than ~.

Your first example allows that, so you could have one with an Int and
> one with a String inside (both are Eqs).
>
>     a = Box 1
>     b = Box "hello"
>
> Now if that first code compiled, your code
>
>     (Box s1) == (Box s2) = s1 == s2
>
> would effectively perform
>
>     ... = 1 == "hello"


Nope.  It would perform (Just 1) == (cast "hello"), which is completely
possible, since (cast "hello") has the same type as (Just 1).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130524/e65f9e5b/attachment.htm>


More information about the Haskell-Cafe mailing list