Skip to content

Instantly share code, notes, and snippets.

@takoeight0821
Created May 31, 2018 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takoeight0821/1fff701fb4631441be13a91465501658 to your computer and use it in GitHub Desktop.
Save takoeight0821/1fff701fb4631441be13a91465501658 to your computer and use it in GitHub Desktop.
これは多相再帰型が一般には推論できないみたいな話なのか
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