User-defined data types Mapping

The constructors of Sum/Product algebraic data types are mapping to tuples in Erlang at compile-time.

Hamler:

  1. -- Sum datatype
  2. data Color = Red | Green | Blue
  3. Red -- {'Red'}
  4. Green -- {'Green'}
  5. Blue -- {'Blue'}
  6. -- Product datatype
  7. data Pair = Pair Integer Integer
  8. Pair 3 4 -- {'Pair',3,4}
  9. -- Maybe
  10. data Maybe a = Just a | Nothing
  11. Nothing -- {'Nothing'}
  12. Just 5 -- {'Just',5}

Erlang:

  1. {'Red'} %% Red
  2. {'Green'} %% Green
  3. {'Blue'} %% Blue
  4. {'Pair',3,4} %% Pair 3 4
  5. {'Nothing'} %% Nothing
  6. {'Just',5} %% Just 5