Questions tagged «monomorphism-restriction»

1
什么是单态性限制?
我对haskell编译器有时会推断出比我期望的少多态的类型感到困惑,例如,在使用无点定义时。 似乎问题出在“单态限制”,在较早版本的编译器上默认启用。 考虑以下haskell程序: {-# LANGUAGE MonomorphismRestriction #-} import Data.List(sortBy) plus = (+) plus' x = (+ x) sort = sortBy compare main = do print $ plus' 1.0 2.0 print $ plus 1.0 2.0 print $ sort [3, 1, 2] 如果我使用它进行编译,则ghc不会得到错误,并且可执行文件的输出为: 3.0 3.0 [1,2,3] 如果我将main主体更改为: main = do print $ …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.