Created
March 20, 2021 10:31
-
-
Save adamse/b416c45a212f56600ad031719bbab91b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module CaseOfCase (f2) where | |
data What = Int Int | TT | FF | |
{-# inline f1 #-} | |
f1 :: Word -> What | |
f1 x = case x of | |
1 -> Int 1 | |
2 -> TT | |
3 -> FF | |
f2 :: Word -> IO () | |
f2 x = case f1 x of | |
Int i -> print i | |
TT -> print True | |
FF -> print False | |
-- inline f1 | |
f2_2 x = case (case x of | |
1 -> Int 1 | |
2 -> TT | |
3 -> FF) of | |
Int i -> print i | |
TT -> print True | |
FF -> print False | |
-- case-of-case | |
f2_3 x = case x of | |
1 -> case Int 1 of | |
Int i -> print i | |
TT -> print True | |
FF -> print False | |
2 -> case TT of | |
Int i -> print i | |
TT -> print True | |
FF -> print False | |
3 -> case FF of | |
Int i -> print i | |
TT -> print True | |
FF -> print False | |
-- case of known constructor | |
f2_4 x = case x of | |
1 -> print 1 | |
2 -> print True | |
3 -> print False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment