Claude Heiland-Allen | 20 Dec 17:03

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

david48 wrote:
| I'm really inexperienced at this :

> class Gadget g where
>   fInit  :: g -> a -> g
> 
> data FString = FString !Int !String deriving Show
> 
> instance Gadget FString where
>   fInit (FString n _) s = FString n (take n s)

The types of:

 > fInit :: g -> a -> g

and:

 > take :: Int -> [a] -> [a]

cause the mismatched types error.

You're trying to apply 'take n' to a value of type 'a' ('take n' 
requires [a]), moreover putting the value of 'take n s' into the FString 
further constrains its type to be [Char] == String.

So either fix the Gadget g class, or fix the Gadget FString instance.

Claude
--

-- 
http://claudiusmaximus.goto10.org

Gmane