[Haskell-cafe] Monad Set via GADT
jbapple+haskell-cafe at gmail.com
Mon Jan 8 20:51:50 EST 2007
On 1/3/07, Roberto Zunino <zunino at di.unipi.it> wrote:
> 1) Why the first version did not typececk?
> 2) Why the second one does?
> 3) If I replace (Teq a w) with (Teq w a), as in
> SM :: Ord w => Teq w a -> Set.Set w -> SetM a
> then union above does not typecheck! Why? I guess the type variable
> unification deriving from matching Teq is not symmetric as I expect it
> to be...
These are very interesting questions that I forgot about until
reminded by Haskell Weekly News. Thanks, HWN!
1) Class constraints can't be used on pattern matching. They ARE
restrictive on construction, however. This is arguably bug in the
Haskell standard. It is fixed in GHC HEAD for datatypes declared in
the GADT way, so as not to break H98 code:
2) The second one works because Class constraints can be used when
pattern matching existentials.
3) I imagine this might have something to do with the coercions that
System FC uses. With one ordering, a coercion might occur that in
another one is unnecessary. This coercion might allow the use of Ord w
by using it before the coercion from S.Set a to S.Set w.
#3 is just a guess.
More information about the Haskell-Cafe