【发布时间】:2011-12-18 11:11:14
【问题描述】:
在 ghci 中:
λ> :t (pure 1)
(pure 1) :: (Applicative f, Num a) => f a
λ> show (pure 1)
<interactive>:1:1:
No instance for (Show (f0 a0))
arising from a use of `show'
Possible fix: add an instance declaration for (Show (f0 a0))
In the expression: show (pure 1)
In an equation for `it': it = show (pure 1)
λ> pure 1
1
这是否意味着ghci执行Applicative并显示结果,就像IO一样?
请注意,pure () 和 pure (+1) 不会打印任何内容。
【问题讨论】:
-
show (pure 1 :: [Int])有效。show (pure 1 :: Maybe Integer)也是。那里没有默认设置,所以 ghci 不知道选择哪种类型。
标签: haskell monads ghci applicative