20 Dec 17:26
Re: Class/Instance : what am I doing wrong in this example ?
Tillmann Rendel <rendel <at> rbg.informatik.tu-darmstadt.de>
2007-12-20 16:26:37 GMT
2007-12-20 16:26:37 GMT
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
or
class Gadget g a where
fInit :: g -> a -> g
instead.
Tillmann
RSS Feed