[Haskell-cafe] Class/Instance : what am I doing wrong in this example ?

Tillmann Rendel rendel at rbg.informatik.tu-darmstadt.de
Thu Dec 20 11:26:37 EST 2007

david48 wrote:
> class Gadget g where
>   fInit  :: g -> a -> g
> data FString = FString !Int !String deriving Show
> instance Gadget FString where

at this point fInit has this type:

   FString -> a -> FString

>   fInit (FString n _) s = FString n (take n s)

but your implementation has this type

   FString -> String -> FString

These types are incompatible, your fInit implementation should be able 
to work with whatever type a the caller has choosen to provide. Maybe 
you should try one of

   class Gadget g where
     fInit  :: g -> String -> g


   class Gadget g a where
     fInit  :: g -> a -> g



More information about the Haskell-Cafe mailing list