Re: A plea for a little Haskell help.

1999-02-17 Thread Fergus Henderson

On 16-Feb-1999, Michael Hobbs [EMAIL PROTECTED] wrote:
 I'm not sure if this can be cleanly done or not. (I've been able to do
 it less-than-cleanly.) What I want to do is define a class where the
 instance has an option of what type of parameters some of its functions
 can accept. For example, say I have
 
 class Foo a where
   write :: a - b - IO ()
 
 This allows a particular instance's version of `write' to accept any
 type of value as the second parameter. However some instances may not be
 able to accept _any_ type of parameter; maybe some can only write
 Strings. I have been able to accomplish what I want by using a bit of a
 kludge:

What's wrong with

class Foo a b where
write :: a - b - IO ()

?

-- 
Fergus Henderson [EMAIL PROTECTED]  |  "Binaries may die
WWW: http://www.cs.mu.oz.au/~fjh  |   but source code lives forever"
PGP: finger [EMAIL PROTECTED]| -- leaked Microsoft memo.






Re: A plea for a little Haskell help.

1999-02-17 Thread Lennart Augustsson


 What's wrong with
 
   class Foo a b where
   write :: a - b - IO ()
 
 ?
Well, it's not Haskell. :-)

  -- Lennart





Re: A plea for a little Haskell help.

1999-02-17 Thread Michael Hobbs

Fergus Henderson wrote:
 
 On 17-Feb-1999, Lennart Augustsson [EMAIL PROTECTED] wrote:
 
   What's wrong with
  
   class Foo a b where
   write :: a - b - IO ()
  
   ?
 
  Well, it's not Haskell. :-)
 
 Oh, good point blush.  I forgot about that.
 
 Please take my mail above as a vote in favour of including
 multi-parameter type classes in Haskell-2! ;-)

Actually, that's very close to what I have implemented in Real Life. I'm
not sure of what the semantic meaning of "multi-parameter type classes"
is, but an example of what I actually have defined is something like:

  class Foo a where
write :: a b - b - IO ()

In which case I define instances such as

  data Fooable b = Fooable (IORef b)
  instance Foo Fooable where
write (Fooable ref) val = ...

Anyway, back to the point. I'm not sure if such a concept has yet been
given a name, but it sure would eliminate a lot of headaches if Haskell
provided something like type patterns. Example:

  class Foo a where
write :: a - b - IO ()
  instance Foo TextEntry where
write te (val :: String) = setText te val
write te (val :: Show a = a) = setText te $ show val
write te val = ioError ...

Right now, the only way I can figure out how to do this is to define
something like
  data Show a = WriteVal a b = WVString String | WVShow a | WVElse b
but this is not easily extendable for ad-hoc situations. (I haven't even
verified if the above statement will really work. I have only done the
MaybePoly)

- Michael Hobbs