Re: [Haskell-cafe] class-instance

2011-01-20 Thread Henning Thielemann
> On 20/01/2011 18:56, Ryan Ingram wrote: >> On Wed, Jan 19, 2011 at 11:56 PM, Patrick Browne >> wrote: >>> I am trying to see what how this requirement can be represented using >>> just the normal instance-implements-class relation for a comparison with >>> a specification language approach. >>>

Re: [Haskell-cafe] class-instance

2011-01-20 Thread Patrick Browne
Ryan, This is exactly what I was looking for. Thanks, Pat On 20/01/2011 18:56, Ryan Ingram wrote: > On Wed, Jan 19, 2011 at 11:56 PM, Patrick Browne > wrote: >> I am trying to see what how this requirement can be represented using >> just the normal instance-implements-class relation for a comp

Re: [Haskell-cafe] class-instance

2011-01-20 Thread Ryan Ingram
On Wed, Jan 19, 2011 at 11:56 PM, Patrick Browne wrote: > I am trying to see what how this requirement can be represented using > just the normal instance-implements-class relation for a comparison with > a specification language approach. > > If there is no simple way to do this using type classe

Re: [Haskell-cafe] class-instance

2011-01-19 Thread Patrick Browne
On 19/01/2011 10:41, Ryan Ingram wrote: > It's still not really clear what you are trying to do. > I am trying to see what how this requirement can be represented using just the normal instance-implements-class relation for a comparison with a specification language approach. If there is no simpl

Re: [Haskell-cafe] class-instance

2011-01-19 Thread Ryan Ingram
I don't think that's exactly what you want, though. name (2::Int) crashes your program. I think you really want a data type. data Person a b = P a b pid :: Person a b -> a pid (P a _) = a pname :: Person a b -> b pname (P _ b) = b Now, what it looks like you want is some kind of extensible re

Re: [Haskell-cafe] class-instance

2011-01-17 Thread Patrick Browne
A functional dependency seems to allow me to express my rather strange requirement. class Person i n | i -> n where pid :: i name :: i -> n instance Person Int String where pid = 1 name(1) = "john" -- name(pid::Int) will produce john Thanks for your help Pat On 17/01/2

Re: [Haskell-cafe] class-instance

2011-01-17 Thread Ketil Malde
Patrick Browne writes: > I think the problem is there is just one constant p1 in the class and > there needs to be multiple constants in the implementation (one for each > person). It seems difficult to specify this using type classes So, some > data declaration as you suggest will probably be n

Re: [Haskell-cafe] class-instance

2011-01-17 Thread Patrick Browne
On 17/01/2011 13:04, Ketil Malde wrote: >> So other PERSONs would have different types, say: I think the problem is there is just one constant p1 in the class and there needs to be multiple constants in the implementation (one for each person). It seems difficult to specify this using type classes

Re: [Haskell-cafe] class-instance

2011-01-17 Thread Ketil Malde
Henning Thielemann writes: >> class PERSON a b where >> p1 :: a >> name :: a -> b A multi-parameter typeclass is a relation over types... >> instance PERSON Int String where >> p1 = 1 >> name p1 = "john" ^--note that this is just an unused paramter, it is clearer to spec

Re: [Haskell-cafe] class-instance

2011-01-17 Thread Patrick Browne
Henning, The code is not intended to fit into a larger application. I am trying to understand instance-implements-class relation. My experiment consists of writing simple English sentences and then seeing how they could be specified and implemented in Haskell. I am sure that this simple requirement

Re: [Haskell-cafe] class-instance

2011-01-17 Thread Henning Thielemann
On Mon, 17 Jan 2011, Patrick Browne wrote: -- My intension is that the PERSON class should *specify* -- that a person has a constant id called p1 -- and that a person has a name that can be found from the id. class PERSON a b where p1 :: a name :: a -> b -- My intension is that the instance

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 "a"s 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), b

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 http://www.haskell.org/m

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 fI

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. T

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 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 f

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] ->