Skip to content

Instantly share code, notes, and snippets.

@nrolland
Created June 9, 2016 09:23
Show Gist options
  • Save nrolland/46cda27c7f81b1192d5bf5fe70355c64 to your computer and use it in GitHub Desktop.
Save nrolland/46cda27c7f81b1192d5bf5fe70355c64 to your computer and use it in GitHub Desktop.
data Tree = Leaf Int
| Node Tree Tree deriving Show
repmin t = tr
where (mn, tr) = walk mn t
walk mn (Leaf n) = (n, Leaf mn)
walk mn (Node t1 t2) = (n1 `min` n2, Node tr1 tr2)
where
(n1, tr1) = walk mn t1
(n2, tr2) = walk mn t2
t = Node (Node (Leaf 10) (Leaf 5)) (Node (Leaf 2) (Node (Leaf 0) (Leaf 10)))
vmintree = repmin t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment