Skip to content

Instantly share code, notes, and snippets.

@tan-yuki
Last active August 29, 2015 14:23
Show Gist options
  • Save tan-yuki/8a5a08716f0ee67661d0 to your computer and use it in GitHub Desktop.
Save tan-yuki/8a5a08716f0ee67661d0 to your computer and use it in GitHub Desktop.

5 高階関数 課題

下記length', all'foldl, foldr, foldl1, foldr1のいずれかを用いて実装せよ。 length', all'の挙動はlength, allを参照すること。

length' :: [a] -> Int

all' :: (a -> Bool) -> [a] -> Bool 

main = do
    print $ length' [1,2,3,4] 
    print $ length' $ replicate 100 1
    print $ all' even [2,4,6]
    print $ all' even [2,4,7]
    print $ all' even [1,3..]

Output:

4
100
True
False
False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment