プログラミング言語論Ⅰ 期末テスト 解答例(2025 年度)

Ⅰ

(1)  take 6 (iterate (* (-2)) 1)

(2)  take 6 (map (1 +) (iterate (* 3) 1 ))

(3)  take 6 (zipWith (+) [1..] (iterate (* 2) 1))

(4)  [ x * y | x <- [1..4], y <- [1..3]]

Ⅱ
(1)
foo [] = 1
foo (x:xs) = if x > 0 && even x
                then x `max` foo xs
                else foo xs

-- max は次のように定義されているが、自分で定義しても良い
-- x `max` y | x > y     = x
--           | otherwise = y
(2)
bar n = [(x,y) | x <- [1 .. n * n], y <- [1 .. x], x * y <= n * n]