【发布时间】:2011-11-30 00:53:17
【问题描述】:
对于以下琐碎的函数定义:
printLength1::(Num a)=>String->a
printLength1 s = length s
printLength2::String->Int
printLength2 s = length s
为什么它们不一样?在什么情况下我应该选择一个而不是另一个?
我得到 printLength1 这个错误:
Couldn't match type `a' with `Int'
`a' is a rigid type variable bound by
the type signature for rpnc :: String -> a at test.hs:20:1
In the return type of a call of `length'
In the expression: length s
In an equation for `rpnc': rpnc s = length s
我理解这个错误。但我该如何解决这个问题? 我已经在这里阅读了一些关于刚性类型变量的帖子,但仍然不明白如何修复它。
【问题讨论】:
标签: haskell