Skip to content

Instantly share code, notes, and snippets.

@pxqr
Created June 8, 2012 02:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pxqr/2893200 to your computer and use it in GitHub Desktop.
Save pxqr/2893200 to your computer and use it in GitHub Desktop.
Question: Deriving boilerplate matching function.
data A = A | B () | C () ()
isA, isB, isC :: A -> Bool
isA A = True
isA _ = False
isB (B _) = True
isB _ = False
isC (C _ _) = True
isC _ = False
extractA :: A -> Maybe ()
extractA A = Just ()
extractA _ = Nothing
extractB :: A -> Maybe ()
extractB (B a) = Just a
extractB _ = Nothing
extractC :: A -> Maybe ((), ())
extractC (C a b) = Just (a, b)
extractC _ = Nothing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment