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

2007-12-20 Thread david48
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

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

2007-12-20 Thread Claude Heiland-Allen
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]

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

2007-12-20 Thread david48
On Dec 20, 2007 5:03 PM, Claude Heiland-Allen [EMAIL PROTECTED] wrote: 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. First of all, thanks a lot for

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

2007-12-20 Thread Tillmann Rendel
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

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

2007-12-20 Thread Jules Bean
Tillmann Rendel wrote: david48 wrote: class Gadget g where fInit :: g - a - g Tillman's two suggestions (below) are probably your answer. Just to say what everyone else has said in a bunch of different ways: your class says that for ANY Gadget, fInit will work with ANY OTHER type a.

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

2007-12-20 Thread david48
On Dec 20, 2007 5:26 PM, Tillmann Rendel [EMAIL PROTECTED] wrote: 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

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

2007-12-20 Thread david48
On Dec 20, 2007 5:44 PM, david48 [EMAIL PROTECTED] wrote: fString :: Int - FString fString n = FString n Oo do I feel dumb for writing this ! Problem solved :) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

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

2007-12-20 Thread david48
On Dec 20, 2007 5:36 PM, Jules Bean [EMAIL PROTECTED] wrote: 2. Maybe you want lots of possible different as for each g. Then you make a a parameter of the class too. 3. Maybe you want just one particular a for each g. I.e. g determines a. Then you can proceed as for (2), but add the