Tillmann Rendel | 20 Dec 17:26
Picon
Favicon

Re: Class/Instance : what am I doing wrong in this example ?

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

Gmane