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

Claude Heiland-Allen claudiusmaximus at goto10.org
Thu Dec 20 11:03:30 EST 2007


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


More information about the Haskell-Cafe mailing list