Skip to content

Instantly share code, notes, and snippets.

@bjartwolf
Last active August 29, 2015 14:14
Show Gist options
  • Save bjartwolf/d59f8e5e3f6a8e68e50e to your computer and use it in GitHub Desktop.
Save bjartwolf/d59f8e5e3f6a8e68e50e to your computer and use it in GitHub Desktop.
kebabs
type Rod = Dagger | Sword | Fork
type Plate = GoldPlate | SilverPlate | BronzePlate
type Bottom = Rod | Plate
type shish<'A> =
Bottom of 'A
| Onion of shish<'A>
| Lamb of shish<'A>
| Tomato of shish<'A>
let rec isVeg kebab =
match kebab with
| Bottom (x) -> true
| Onion (x) -> isVeg x
| Lamb (x) -> false
| Tomato (x) -> isVeg x
let aBab = Onion(Tomato (Onion(Bottom GoldPlate)))
let anotherBab = Onion(Lamb(Onion(Tomato(Bottom 53))))
(isVeg aBab).Dump()
(isVeg anotherBab).Dump()
let rec WhatBottom kebab =
match kebab with
| Bottom (x) -> x
| Onion (x) -> WhatBottom x
| Lamb (x) -> WhatBottom x
| Tomato (x) -> WhatBottom x
(WhatBottom aBab).Dump()
(WhatBottom anotherBab).Dump()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment