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:
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
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 =