[英]Confuse about pure in applicative functor
I have following example with pure
function: 我有以下具有
pure
函数的示例:
Prelude> :t pure ((+1) 1)
pure ((+1) 1) :: (Num a, Applicative f) => f a
What is above the concrete type of f
wrapped a
? f
包裹a
的具体类型之上是什么?
For example, the f
(structure) is here Maybe: 例如,
f
(结构)可能在这里:
Prelude> pure ((+1) 1) :: Maybe Int
Just 2
and what is the structure of: 以及什么是结构:
pure ((+1) 1)
? ?
The second example: 第二个例子:
Prelude> :t pure ((+1) 1) :: [Int]
pure ((+1) 1) :: [Int] :: [Int]
Why does the GHCi show the type twice, namely :: [Int] :: [Int]
not only :: [Int]
? 为什么GHCi会两次显示类型,即
:: [Int] :: [Int]
不仅:: [Int]
?
f
and a
are both type variables. f
和a
都是类型变量。 There is no concrete type. 没有具体类型。 It will use whatever type is required by the surrounding context.
它将使用周围上下文所需的任何类型。
When you type :t EXPR
, ghci prints the type as EXPR :: TYPE
. 当键入
:t EXPR
,ghci将类型打印为EXPR :: TYPE
。 The first :: [Int]
is part of the expression you typed; 第一个
:: [Int]
是您键入的表达式的一部分; the second :: [Int]
is the type computed by ghci. 第二个
:: [Int]
是ghci计算的类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.