Re: [Haskell-cafe] run-time type testing in haskell?

2007-04-28 Thread Udo Stenzel
Eric wrote: > (1) Have Handlers implement a method handle(m: Msg). To add new types of > message, we declare message types which extend Msg. The Handler then > uses runtime type testing to decide how to deal with each message. The > advantage of this design is that we can add new Handler and new

Re: [Haskell-cafe] run-time type testing in haskell?

2007-04-28 Thread Neil Mitchell
Hi Eric I thought about that. But consider the following scenario. We have a Dispatcher and a Handler. The Dispatcher sends messages to Handlers. There are two ways we could implement this in an OOP language "Consider how to implement OO features in Haskell"... Lets not, rather instead lets t

Re[2]: [Haskell-cafe] run-time type testing in haskell?

2007-04-28 Thread Bulat Ziganshin
Hello Eric, Saturday, April 28, 2007, 5:33:02 PM, you wrote: > Type classes allow us to adopt approach (0) in Haskell, but don't seem > to allow approach (1) may be multi-parameter type class is what you need here, may be just closure. anyway, OOP may be simulated in Haskell via hierarchy of

Re: [Haskell-cafe] run-time type testing in haskell?

2007-04-28 Thread Eric
Robin Green wrote: In object-oriented languages you can achieve the same effect by defining a method on each type which has different behaviour depending on the type. In Haskell you can achieve much the same effect by defining methods in typeclasses and then defining instances for types. It's q

Re: [Haskell-cafe] run-time type testing in haskell?

2007-04-28 Thread Robin Green
On Sat, 28 Apr 2007 14:06:21 +0100 Eric <[EMAIL PROTECTED]> wrote: > In imperative languages one can test the type of a variable and > downcast if necessary. Here's an example in Pseudojava: > > T v := ... ; > if (v instanceof T') T' v' := (T')v In object-oriented languages you can achieve the s

Re: [Haskell-cafe] run-time type testing in haskell?

2007-04-28 Thread Stefan O'Rear
On Sat, Apr 28, 2007 at 02:06:21PM +0100, Eric wrote: > In imperative languages one can test the type of a variable and downcast > if necessary. Here's an example in Pseudojava: > > T v := ... ; > if (v instanceof T') T' v' := (T')v > > Is it possible to do something like this in Haskell? Possi

[Haskell-cafe] run-time type testing in haskell?

2007-04-28 Thread Eric
In imperative languages one can test the type of a variable and downcast if necessary. Here's an example in Pseudojava: T v := ... ; if (v instanceof T') T' v' := (T')v Is it possible to do something like this in Haskell? Eric. ___ Haskell-Cafe mail