nicojensen.de/vendor/bundle/gems/rouge-3.3.0/lib/rouge/demos/fsharp
Nico Jensen b59a203dbb Init
Init commit
2019-03-12 13:49:49 +01:00

12 lines
No EOL
316 B
Text
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(* 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