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

david48 dav.vire+haskell at gmail.com
Thu Dec 20 10:47:52 EST 2007


I'm really inexperienced at this :

-----------
{-# OPTIONS_GHC -fglasgow-exts -funbox-strict-fields
-fallow-undecidable-instances -O2 #-}

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)

-------------

I get the error message :
     Couldn't match expected type `String' against inferred type `a'
      `a' is a rigid type variable bound by
    the type signature for `fInit' at Gadget.hs:4:17
    In the second argument of `FString', namely `s'
    In the expression: FString n s
    In the definition of `fInit': fInit (FString n _) s = FString n s


More information about the Haskell-Cafe mailing list