[Haskell-cafe] Assorted AT fun and games
Andrew Coppin
andrewcoppin at btinternet.com
Sun Aug 15 13:06:58 EDT 2010
Brandon S Allbery KF8NH wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 8/15/10 09:00 , Andrew Coppin wrote:
>
>> class (Vector (Point x)) => HasSpace x where
>> type Point x :: *
>>
> (...)
>
>> And now things get *really* interesting. Consider this:
>>
>> data Foo x = Foo !x !(Point x)
>>
>> Surprisingly, GHC accepts this. This despite the rather obvious fact that
>> "Point x" can exist if and only if "x" has a HasSpace instance. And yet, the
>> type definition appears to say that "x" is simply an unconstrained type
>> variable. Intriguing...
>>
>
> Maybe I'm missing something in all the type machinery I elided, but it looks
> to me like you have that backwards: HasSpace x requires Point x but not
> vice versa. Your actual usage may require the reverse association, but the
> definition of Foo won't be modified by that usage --- only applications of
> that definition.
>
Well, since Point is part of the definition of HasSpace, and therefore
Point x is defined only if an instance HasSpace x exists. I'm not sure
how that's "Point x doesn't require HasSpace x".
More information about the Haskell-Cafe
mailing list