fork download
  1. type btree = Node of ((btree * btree) * int) | Leaf of int;;
  2.  
  3. type 't beverage = Beer of string | Wine of string | Coffee of string | Beverages of ('t beverage * 't beverage);;
  4.  
  5. let mytree = Node ((Leaf 2, Node ((Leaf 4, Leaf 5), 3)), 1);;
  6.  
  7.  
  8. let rec convert x =
  9. match x with
  10. | Beer brand -> "It's a beer brand"
  11. | Wine brand -> "It's a wine brand"
  12. | Coffee brand -> brand
  13. | Beverages (x, y) -> convert x;;
  14.  
  15. let rec map (f: int -> int) l =
  16. match l with
  17. | [] -> []
  18. | x::xs -> f x :: map f xs;;
  19.  
  20. let l: int list = [1; 2; 3; 4];;
  21.  
  22. let rec fold (f: int -> int -> int) (acc: int) (l: int list) =
  23. match l with
  24. | [] -> acc
  25. | x::xs -> fold f (f acc x) xs;;
  26.  
  27. let mydrinks = Beverages (Beer "Harley", Wine "Queen!");;
  28. let coffee = convert mydrinks;;
Success #stdin #stdout 0.01s 2780KB
stdin
Standard input is empty
stdout
Standard output is empty