datatypes.sml 342 B

1234567891011
  1. (* datatype example -- single and pair list *)
  2. datatype ('a, 'b) element =
  3. Pair of 'a * 'b
  4. | Single of 'a;
  5. fun sum_elem_list nil = 0
  6. | sum_elem_list (Single(x)::rest) = sum_elem_list rest
  7. | sum_elem_list (Pair(x, y)::rest) = y + (sum_elem_list rest);
  8. sum_elem_list [Pair ("in", 6), Single "function", Pair ("as", 2)];