Skip to content

Instantly share code, notes, and snippets.

@lironsade
Created November 20, 2018 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lironsade/2f54bc6285b23b4ee3b9507863e87a18 to your computer and use it in GitHub Desktop.
Save lironsade/2f54bc6285b23b4ee3b9507863e87a18 to your computer and use it in GitHub Desktop.
data NiceTree = R | B | Node [NiceTree] deriving (Show, Eq)
exmpl = Node [Node [R, B, B], Node [B], Node [R, R], Node [B]]
eval :: NiceTree -> NiceTree
eval R = R
eval B = B
eval (Node xs)
| res == 0 = error "can't compute tie"
| res > 0 = R
| res < 0 = B
where res = foldr (\x acc -> if (eval x) == R then acc + 1 else acc -1) 0 xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment