-
无限循环一个列表
cycle :: [a] -> [a]
cycle xs = xs ++ cycle xs -
给出2的幂
使用pot,直接用map函数
powt = map pot [0…]
不使用pot,使用recursion
powt = 1: map (2*) powt
和例子nats的生成相似(见VL 10) -
给出n次幂
用take把n个x从无限的列表[x, x…]中取出,然后用foldr做乘法
pow2 :: Int -> Int -> Int
pow2 x n = foldr (*) 1 (take n [x, x…])
Haskell笔记 无限的列表
最新推荐文章于 2021-07-22 00:16:15 发布