【发布时间】:2020-11-01 17:36:59
【问题描述】:
我想知道如何在 GHCI 中映射 IO [Int]。
λ: :{
λ| th :: IO [Int]
λ| th = pure [1, 2, 3, 4]
λ| :}
λ: th
[1,2,3,4]
λ: :t th
th :: IO [Int]
λ: map (+2) th
• Couldn't match expected type ‘[b]’ with actual type ‘IO [Int]’
• In the second argument of ‘map’, namely ‘th’
In the expression: map (+ 2) th
想要的结果:
λ: res = map (+2) th -- <-- some working version of this
λ: res
[3, 4, 5, 6]
λ: :t res
res :: IO [Int]
解决方案可能很明显,但不知何故我无法理解它。
【问题讨论】: