Skip to content

Instantly share code, notes, and snippets.

@paf31
Created June 4, 2015 06:28
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 paf31/9b901a2b83690cee75e3 to your computer and use it in GitHub Desktop.
Save paf31/9b901a2b83690cee75e3 to your computer and use it in GitHub Desktop.
Exhaustivity checking by tree coloring
module Tree where
data Binder = Wildcard | Zero | Succ Binder deriving (Show)
data Tree = Covered | Uncovered | Branch Tree Tree
color :: Tree -> Binder -> Tree
color _ Wildcard = Covered
color Covered _ = Covered
color Uncovered Zero = Branch Covered Uncovered
color Uncovered (Succ b) = Branch Uncovered (color Uncovered b)
color (Branch z s) Zero = Branch Covered s
color (Branch z s) (Succ b) = Branch z (color s b)
check :: [Binder] -> Bool
check = covered . foldl color Uncovered
covered :: Tree -> Bool
covered Covered = True
covered (Branch z s) = covered z && covered s
covered _ = False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment