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 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 quite
analogous. This is the recommended way of doing it in Haskell.
-- 
Robin
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to