
28 Apr
2007
28 Apr
'07
9:14 a.m.
On Sat, 28 Apr 2007 14:06:21 +0100
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
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