Last active
December 14, 2015 03:59
-
-
Save exterm/5024877 to your computer and use it in GitHub Desktop.
Haskell underestimates parameter types and overestimates return types.
This file contains hidden or 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
| and _ False = False | |
| and False _ = False | |
| and _ _ = True | |
| -- inferred type: Bool -> Bool -> Bool | |
| -- underestimated parameter type: the function would also work called like this: | |
| and 42 False | |
| -- and return False; the type checker throws an error for this though. | |
| and' _ False = 0 | |
| and' False _ = 0 | |
| and' _ _ = 1 | |
| -- inferred type: Num a => Bool -> Bool -> a | |
| -- but no values other than 0 or 1 can be returned. The return type could theoretically be 0 | 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment