诚然,我是 Haskell 新手。为了探索惰性,我在 ghci 中创建了一个函数,它返回它的第二个参数:
Prelude> let latter x y = y
latter :: t -> t1 -> t1
我可以使用 、 、 、 和 (以小数表示)类型的Char
参数[Char]
来Num
调用Floating
它Fractional
:
Prelude> latter 'x' 'y'
'y'
it :: Char
Prelude> latter "foo" "bar"
"bar"
it :: [Char]
Prelude> latter 1 2
2
it :: Num t1 => t1
Prelude> latter pi pi
3.141592653589793
it :: Floating t1 => t1
Prelude> latter 0.5 0.7
0.7
it :: Fractional t1 => t1
latter
当我尝试将a 应用于以Fractional
比率表示时,为什么会出现可怕的错误(以及这是什么意思) :
Prelude> 1/2
0.5
it :: Fractional a => a
Prelude> latter 1/2 1/2
<interactive>:62:1:
Could not deduce (Num (a0 -> t1 -> t1))
arising from the ambiguity check for ‘it’
from the context (Num (a -> t1 -> t1),
Num a,
Fractional (t1 -> t1))
bound by the inferred type for ‘it’:
(Num (a -> t1 -> t1), Num a, Fractional (t1 -> t1)) => t1 -> t1
at <interactive>:62:1-14
The type variable ‘a0’ is ambiguous
When checking that ‘it’
has the inferred type ‘forall t1 a.
(Num (a -> t1 -> t1), Num a, Fractional (t1 -> t1)) =>
t1 -> t1’
Probable cause: the inferred type is ambiguous