[Haskell-cafe] Can sub-classes inheriting instances of parent class?

2009-07-25 Thread Szekeres István
Hi, I'm trying to do something like the following: class Foo a where doit :: (String - IO ()) - a - IO () instance Foo Int where doit f = f . show instance Foo Char where doit f = f . (:[]) So now I have a doit function for Ints and Chars, that takes a function and does the IO

classes and instances

2001-10-04 Thread Russo, Tom
Hello, I'm learning haskell and I'm having some trouble with type classes. I understand them conceptually, but when I try to create an instance I run into problems. As a simple example, I create a class called ToInt: class ToCh a where int :: a - Int Then I create an

Re: classes and instances

2001-10-04 Thread Ashley Yakeley
At 2001-10-04 08:31, Russo, Tom wrote: Main int 5 ERROR - Unresolved overloading *** Type : (Num a, ToInt a) = Int *** Expression : int 5 Can someone explain what the problem is, and how to interpret the error message I'm getting? Oh, 5 isn't necessarily an Int. It's of type Num a = a,

Re: classes and instances

1998-06-08 Thread Peter White
Simon writes: You correctly say that you want a still more specific type. Without understanding your application better I am nervous about recommending this, but you *can* get what you say you want by using a multi-parameter class class Weird a b c where ... f2

Re: classes and instances

1998-06-08 Thread Simon L Peyton Jones
data Weirder a b = Weirdest a b class Weird c where f1 :: c - c f2 :: Weirder a b - c - Weirder a b f3 :: Weirder a c - Weirder c a f4 :: c - c - Bool instance Weird (d,e) where f1 (x,y) = (x,y) f2 w (x,y) = Weirdest x y f3 (Weirdest x y) = Weirdest y x

Re: classes and instances

1998-06-08 Thread Peter White
: classes and instances MIME-Version: 1.0 On Mon, 8 Jun 1998, Peter White wrote: | What I really want is to define a pool of reusable resources. So | I want a class declaration something like: | | class ResourcePool p where | newp :: p - e - p -- adds new element e to the resource pool p