Created
March 29, 2011 17:14
-
-
Save maoe/892787 to your computer and use it in GitHub Desktop.
phantom typeの型推論
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
data Term t = Zero | |
| Succ (Term Int) | |
| Pred (Term Int) | |
| IsZero (Term Int) | |
| If (Term Bool) (Term Int) (Term Int) | |
-- eval :: Term t -> T | |
eval Zero = I 0 | |
eval (Succ e) = I $ succ $ int $ eval e | |
eval (Pred e) = I $ pred $ int $ eval e | |
eval (IsZero e) = B $ int (eval e) == 0 | |
eval (If b t e) = if bool (eval b) then eval t else eval e | |
data T = I { int :: Int } | |
| B { bool :: Bool } | |
deriving Show | |
{- eval (If b t e)の節で型エラー。evalの型を明示すれば型チェックは通る。 | |
Couldn't match expected type `Int' with actual type `Bool' | |
Expected type: Term Int | |
Actual type: Term Bool | |
In the first argument of `eval', namely `b' | |
In the first argument of `bool', namely `(eval b)' | |
Failed, modules loaded: none. | |
-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment