let updateFunc = updatedMaybeProperty srcTitle targetTitle :: (Title -> Maybe a) -> Maybe a
_ = updateFunc (titleVersion :: Title -> Maybe Text)
_ = updateFunc (titleYearProduced :: Title -> Maybe Integer)
我在第3行中收到此错误:
• Couldn't match type ‘Text’ with ‘Integer’
Expected type: Title -> Maybe Text
Actual type: Title -> Maybe Integer
• In the first argument of ‘updateFunc’, namely
‘(titleYearProduced :: Title -> Maybe Integer)’
很显然,在第2行中,编译器会推断Maybe a
的类型,并确定a
必须始终为Text
。
如何防止这种情况并使updateFunc
成为“泛型”,以便它与a
的不同类型兼容?
答案 0 :(得分:6)
尝试注释绑定,而不是表达式。
let updateFunc :: (Title -> Maybe a) -> Maybe a
updateFunc = updatedMaybeProperty srcTitle targetTitle
_ = updateFunc (titleVersion :: Title -> Maybe Text)
_ = updateFunc (titleYearProduced :: Title -> Maybe Integer)