Trouble with type signatures and type families

Hi, consider the following code: ---------------------------- class Foo f where type Bar f :: * type Baz f :: * from :: Bar f -> Baz f to :: Baz f -> Bar f data Tree a b c = Empty | Tree b c (Tree a b c) (Tree a b c) --singleton :: (Foo f) => Bar f -> Tree a (Bar f) (Baz f) singleton x = Tree x (from x) Empty Empty ---------------------------- what type does 'singleton' have? ghci-6.10.2 says:
:t singleton singleton :: forall f a. (Foo f) => Bar f -> Tree a (Bar f) (Baz f)
which is no surprise. But when I uncomment the type signature in the above code sample, loading it to ghci gives the following error:
:r [1 of 1] Compiling Main ( T.hs, interpreted )
T.hs:14:22: Couldn't match expected type `Baz f1' against inferred type `Baz f' In the second argument of `Tree', namely `(from x)' In the expression: Tree x (from x) Empty Empty In the definition of `singleton': singleton x = Tree x (from x) Empty Empty T.hs:14:27: Couldn't match expected type `Bar f' against inferred type `Bar f1' In the first argument of `from', namely `x' In the second argument of `Tree', namely `(from x)' In the expression: Tree x (from x) Empty Empty Failed, modules loaded: none. I don't get it... what's wrong, I just copied the inferred type? //Stephan -- Früher hieß es ja: Ich denke, also bin ich. Heute weiß man: Es geht auch so. - Dieter Nuhr

You may want to read the comments at http://hackage.haskell.org/trac/ghc/ticket/1897.

Gleb Alexeyev wrote:
You may want to read the comments at http://hackage.haskell.org/trac/ghc/ticket/1897.
Wow that's subtle... Thanks a lot! -- Früher hieß es ja: Ich denke, also bin ich. Heute weiß man: Es geht auch so. - Dieter Nuhr
participants (2)
-
Gleb Alexeyev
-
Stephan Friedrichs