Fwd: [Haskell-beginners] RankNTypes + ConstraintKinds to use Either as a "union"

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Fwd: [Haskell-beginners] RankNTypes + ConstraintKinds to use Either as a "union"

Thiago Negri

Why type inference can't resolve this code?

> {-# LANGUAGE RankNTypes, ConstraintKinds #-}
> bar :: (Num a, Num b) => (forall c. Num c => c -> c) -> Either a b -> Either a b
> bar f (Left a) = Left (f a)
> bar f (Right b) = Right (f b)
> bar' = bar (+ 2) -- This compiles ok
> foo :: (tc a, tc b) => (forall c. tc c => c -> c) -> Either a b -> Either a b
> foo f (Left a) = Left (f a)
> foo f (Right b) = Right (f b)
> foo' = foo (+ 2) -- This doesn't compile because foo' does not typecheck
> -- Kim-Ee pointed out that this works:
> type F tc a b =  (tc a, tc b) => (forall c. tc c => c -> c) -> Either a b -> Either a b
> foo' = (foo :: F Num a b) (+2)


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe