[Haskell-cafe] GADT and instance deriving
Niklas Hambüchen
mail at nh2.me
Sat May 25 06:08:19 CEST 2013
On 25/05/13 06:06, Alexander Solla wrote:
> On Fri, May 24, 2013 at 10:41 AM, Niklas Hambüchen <mail at nh2.me
> <mailto: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:
Sorry, I didn't formulate that clearly: I meant to describe what the
problem in the complaint about s1 ~ s2 is, not what s1 ~ s2 means.
> Your first example allows that, so you could have one with an Int and
> one with a String inside (both are Eqs).
>
> ...
>
> Nope. It would perform (Just 1) == (cast "hello"), which is completely
> possible, since (cast "hello") has the same type as (Just 1).
That's why I said "your first example"; there is no cast in it.
More information about the Haskell-Cafe
mailing list