我已经看到pure 1
的类型是(Num a, Applicative f) => f a
,这很明显。 所以,如果我想使它成为一个Maybe Int
:Haskell - Applicative/Monad实例
Prelude> pure 1 :: Maybe Int
Just 1
这个怎么样?
Prelude> pure 1
1
Prelude> return 1
1
这是怎么回事?为什么不抱怨不知道选择哪个实例?
编辑
我认为这个行为实际上已经无关单子或applicatives,但是这是我来到它的背景下...
请参阅[提示时的I/O操作]中的'返回True'(https://downloads.haskell.org/~ghc/7.8.4/docs/html/users_guide/interactive-evaluation.html) –