[Haskell-cafe] Type Mismatch

Tillmann Rendel rendel at rbg.informatik.tu-darmstadt.de
Mon Jan 7 09:35:56 EST 2008


Cetin Sert wrote:
> class Streamable a where
>   to :: a -> Stream a

The type of to looks wrong for me. a -> Stream a means to takes a single 
element into a stream of such elements, but you probably want to convert 
between different representations of streams of elements.

> toStream :: [a] -> Stream a
> 
> instance Streamable [a] where
>   to = toStream                       -- ERROR: see below

Here to :: [a] -> Stream [a] and toStream :: [a] -> Stream a. These 
types are different, as ghc complained.

Possible solutions include multi parameter type classes

   class Streamable s a where
     to :: s -> Stream a

   instance Streamable [a] a where
     to = toStream

and constructor classes

   class Streamable s where
     to :: s a -> Stream a

   instance Streamable [] where
     to = toStream

Tillmann


More information about the Haskell-Cafe mailing list