Created
May 31, 2018 10:51
-
-
Save takoeight0821/1fff701fb4631441be13a91465501658 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
data T = A | B | C T | |
deriving (Show, Eq) | |
class HasT a where | |
t :: a -> T | |
instance HasT T where | |
t = id | |
instance HasT a => HasT (Maybe a) where | |
t Nothing = B | |
t (Just x) = t x | |
-- f :: T -> Bool と型推論される | |
-- f :: HasT a => a -> Bool と注釈を付けることもできる | |
-- 多相再帰? | |
f x = | |
case t x of | |
A -> True | |
B -> False | |
C t' -> f t' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment