type btree
= Node
of ((btree
* btree
) * int) | Leaf
of int;;
type 't beverage
= Beer
of string | Wine
of string | Coffee
of string | Beverages
of ('t beverage
* 't beverage
);;
let mytree = Node ((Leaf 2, Node ((Leaf 4, Leaf 5), 3)), 1);;
let rec convert x =
match x with
| Beer brand -> "It's a beer brand"
| Wine brand -> "It's a wine brand"
| Coffee brand -> brand
| Beverages (x, y) -> convert x;;
let rec map
(f
: int -> int) l
= match l with
| [] -> []
| x::xs -> f x :: map f xs;;
match l with
| [] -> acc
| x::xs -> fold f (f acc x) xs;;
let mydrinks = Beverages (Beer "Harley", Wine "Queen!");;
let coffee = convert mydrinks;;
dHlwZSBidHJlZSA9IE5vZGUgb2YgKChidHJlZSAqIGJ0cmVlKSAqIGludCkgfCBMZWFmIG9mIGludDs7CiAKdHlwZSAndCBiZXZlcmFnZSA9IEJlZXIgb2Ygc3RyaW5nIHwgV2luZSBvZiBzdHJpbmcgfCBDb2ZmZWUgb2Ygc3RyaW5nIHwgQmV2ZXJhZ2VzIG9mICgndCBiZXZlcmFnZSAqICd0IGJldmVyYWdlKTs7CiAKbGV0IG15dHJlZSA9IE5vZGUgKChMZWFmIDIsIE5vZGUgKChMZWFmIDQsIExlYWYgNSksIDMpKSwgMSk7OwogCiAKbGV0IHJlYyBjb252ZXJ0IHggPQogICAgbWF0Y2ggeCB3aXRoCiAgICAgICAgfCBCZWVyIGJyYW5kIC0+ICJJdCdzIGEgYmVlciBicmFuZCIKICAgICAgICB8IFdpbmUgYnJhbmQgLT4gIkl0J3MgYSB3aW5lIGJyYW5kIgogICAgICAgIHwgQ29mZmVlIGJyYW5kIC0+IGJyYW5kCiAgICAgICAgfCBCZXZlcmFnZXMgKHgsIHkpIC0+IGNvbnZlcnQgeDs7CiAKbGV0IHJlYyBtYXAgKGY6IGludCAtPiBpbnQpIGwgPQogICAgICAgIG1hdGNoIGwgd2l0aAogICAgICAgIHwgW10gLT4gW10KICAgICAgICB8IHg6OnhzIC0+IGYgeCA6OiBtYXAg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