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:
 http://okmij.org/ftp/Haskell/generics.html

Thank you.

Is there any interest in adding polymorphic variants to Haskell? I think it is 
fair to say that OCaml has shown them to be an extremely useful construct 
(more common than objects in OCaml, for example).

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
OCaml for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists/?e
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[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 = fun

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
OCaml for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists/?e
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe