rf-web/vendor/bundle/gems/rouge-3.12.0/lib/rouge/demos/fsharp

12 lines
316 B
Plaintext
Raw Normal View History

2019-10-21 08:18:17 +00:00
(* Binary tree with leaves car­rying an integer. *)
type Tree = Leaf of int | Node of Tree * Tree
let rec existsLeaf test tree =
match tree with
| Leaf v -> test v
| Node (left, right) ->
existsLeaf test left
|| existsLeaf test right
let hasEvenLeaf tree =
existsLeaf (fun n -> n % 2 = 0) tree