the type of 1+ is given as :
Prelude> :t (1+)
(1+) :: Num a => a -> a
Is the correct way to read this function as :
1+ takes a Num and returns a function of type a -> a
?
答案 0 :(得分:5)
1+
takes an a
and returns an a
with the restriction that a
must be an instance of Num
.
答案 1 :(得分:4)
No, Num a
is a class constraint, which is implied by the different arrow (=>
).
+1
is a function from a
to a
where a
must be an instance of the Num
typeclass.
For more information see the part of Learn you a Haskell.
答案 2 :(得分:0)
不,在Haskell中= =>之前的部分表示参数必须是其实例的类约束。所以,
(1+) :: Num a => a -> a
这意味着(1+)是一个函数,它接受参数“a”并返回参数“a”,其中参数“a”必须是类约束Num的实例。
在这里,您可以看到Num类约束的完整定义:http://hackage.haskell.org/package/base-4.9.0.0/docs/Prelude.html#t:Num