[Haskell-cafe] Polymorphic variants

Jon Harrop jon at ffconsultancy.com
Wed Jul 25 18:04:16 EDT 2007


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


More information about the Haskell-Cafe mailing list