【发布时间】:2015-09-19 01:49:01
【问题描述】:
除了可读性和失去一般性之外,以下定义有什么问题:
maxPlusOne :: (Ord a, Num a) => a -> a -> a
maxPlusOne = (1+) . max
编译器会抱怨它不能从+ 推导出Num (a -> a)。
但在我看来它需要的是Num a => a -> a,这正是(1+)的类型。
这是错误:
<interactive>:5:52:
Could not deduce (Num (a -> a)) arising from a use of ‘+’
from the context (Ord a, Num a)
【问题讨论】:
-
Num a => a -> a不是(1+)的类型。 -
@ErikAllik:是的。如果我在 ghci 中输入
:t (1+),它会告诉我(1+) :: Num a => a -> a- 就是这样。 -
(但那当然和
Num a => Num (a -> a)不一样)