Created
January 18, 2012 09:36
-
-
Save einblicker/1632170 to your computer and use it in GitHub Desktop.
多相再帰の例
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 Seq a = Nil | Cons a (Seq (a,a)) | |
-- 多相再帰の型推論は完全ではないので、 | |
-- このように型アノテーションをコメントアウトすると | |
-- コンパイルできない | |
-- len :: Seq a -> Int | |
len Nil = 0 | |
len (Cons x s) = 1 + 2 * (len s) | |
pair f (x,y) = (f x, f y) | |
-- mapseq :: (a -> b) -> Seq a -> Seq b | |
mapseq f Nil = Nil | |
mapseq f (Cons x xs) = Cons (f x) (mapseq (pair f) xs) | |
main = return () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment