Re: [Haskell-cafe] Polymorphic variants

2007-08-02 Thread Jon Harrop
On Thursday 26 July 2007 00:07:23 Josef Svenningsson wrote: On 7/26/07, Jon Harrop [EMAIL PROTECTED] wrote: Does Haskell have anything similar to OCaml's polymorphic variants? No as such, but it's possible to simulate them. As always Oleg was the one to demonstrate how:

Re: [Haskell-cafe] Polymorphic variants

2007-07-25 Thread Josef Svenningsson
On 7/26/07, Jon Harrop [EMAIL PROTECTED] wrote: Does Haskell have anything similar to OCaml's polymorphic variants? No as such, but it's possible to simulate them. As always Oleg was the one to demonstrate how: http://okmij.org/ftp/Haskell/generics.html Cheers, Josef

[Haskell-cafe] Polymorphic variants

2007-07-25 Thread Jon Harrop
Does Haskell have anything similar to OCaml's polymorphic variants? They act as inferred sum types: # let rec eval = function | `Int n - n | `Add(f, g) - eval f + eval g | `Mul(f, g) - eval f * eval g;; val eval : ([ `Add of 'a * 'a | `Int of int | `Mul of 'a * 'a ] as 'a) - int =