Re: [Haskell-cafe] Instances of constrained datatypes

2005-04-08 Thread Keean Schupke
Can you not define functor like Hughes defines a restricted monad (section 3 in the paper)... Keean Arjun Guha wrote: One way to do roughly what you want is to pass the dictionary yourself: >data EqDict a = EqDict { >leq :: a -> a -> Bool } > >data EqList a = EqList (EqDict a) [

[Haskell-cafe] List containing different types but all implementing the same class

2005-04-08 Thread Bo Herlin
Hi everyone. Being new to Haskell I wonder how I can make a list contain different types but all implementing the same class, like this: data X = X data Y = Y class Z a where f :: a -> Int instance Z X where f x = 0 instance Z Y where f y = 1 test1 :: Z a => [a] test1 = [X,Y] test2 = map f test1

Re: [Haskell-cafe] List containing different types but all implementing the same class

2005-04-08 Thread Keean Schupke
You can do this like: >data TTrue = TTrue >data TFalse = TFalse > >data Nil = Nil >data Cons a l = Cons a l > >class Constrain c a b | c a -> b where >constrain :: c -> a -> b > >data ZConstraint = ZConstraint >instance Z a b => Constrain ZConstraint a b > >class List c l >instance List c Nil >

Re: [Haskell-cafe] List containing different types but all implementing the same class

2005-04-08 Thread Mark Carroll
On Fri, 8 Apr 2005, Bo Herlin wrote: (snip) > Is it possible to make this work? This is an extension beyond the 1998 standard, but http://haskell.org/hawiki/ExistentialTypes may be interesting to you. -- Mark ___ Haskell-Cafe mailing list Haskell-Cafe@