Polymorphic Recursion / Rank-2 Confusion

Dominic Steinitz dominic.steinitz at blueyonder.co.uk
Sat Sep 20 13:01:32 EDT 2003


Can anyone tell me why the following doesn't work (and what I have to do to
fix it)? I thought by specifying the type of coalw as rank-2 would allow it
to be used both at a and (a,b).

Dominic.

Reading file "Test.hs":tten
Type checking
ERROR "Test.hs":18 - Inferred type is not general enough
*** Expression    : \(w1,w2) -> coalw w1 ++ coalw w2
*** Expected type : a -> [b]
*** Inferred type : (a,b) -> [c]

data Vector_ v w =
     Zero v
   | Even (Vector_     v (w,w))
   | Odd  (Vector_ (v,w) (w,w))
   deriving Show

vzero = Zero ()
vone = Odd (Zero ((),'a'))
vtwo = Even (Odd (Zero ((),('a','b'))))
vthree = Odd (Odd (Zero (((),'a'),('b','c'))))
vfour = Even (Even (Odd (Zero ((),(('a','b'),('c','d'))))))

coal_ :: (forall a b. a -> [b]) ->
         (forall c d. c -> [d]) ->
         Vector_ v w -> [w]
coal_ coalv coalw (Zero v) =
   coalv v
coal_ coalv coalw (Even v) =
   coal_ coalv
         (\(w1,w2) -> (coalw w1) ++ (coalw w2))
         v
coal_ coalv coalw (Odd v) =
   coal_ (\(v,w) -> (coalv v) ++ (coalw w))
         (\(w1,w2) -> (coalw w1) ++ (coalw w2))
         v





More information about the Haskell mailing list