为了更深入地了解表达式评估中涉及的中间步骤,我想尝试一下(http://hackage.haskell.org/package/hood)包。
在软件包的主页(http://ku-fpg.github.io/software/hood/)上,有一些引擎功能的例子,即这个例子:
import Debug.Hood.Observe
ex2 = print
. reverse
. (observe "intermediate")
. reverse
$ [1..9]
n = runO ex2
当我尝试运行此示例时,出现以下错误:
hoodTests.hs:10:10: error:
• Ambiguous type variable ‘a0’ arising from the literal ‘1’
prevents the constraint ‘(Num a0)’ from being solved.
Probable fix: use a type annotation to specify what ‘a0’ should be.
These potential instances exist:
instance Num Integer -- Defined in ‘GHC.Num’
instance Num Double -- Defined in ‘GHC.Float’
instance Num Float -- Defined in ‘GHC.Float’
...plus two others
(use -fprint-potential-instances to see them all)
• In the expression: 1
In the second argument of ‘($)’, namely ‘[1 .. 9]’
In the expression:
print . reverse . (observe "intermediate") . reverse $ [1 .. 9] Failed, modules loaded: none.
我想这意味着[1..9]应该有明确的类型,例如Int
或Float
。
然后我改变了这样的脚本:
import Debug.Hood.Observe
al :: [Int]
al = [0..9]
ex2 = print
. reverse
. (observe "intermediate")
. reverse
$ al
n = runO ex2
现在错误已消失,但输出不符合预期。而不是
[0,1,2,3,4,5,6,7,8,9]
-- intermediate
9 : 8 : 7 : 6 : 5 : 4 : 3 : 2 : 1 : 0 : []
输出
*Main> n
[0,1,2,3,4,5,6,7,8,9]
*Main>
我认为包装是旧的,它最后更新为ghc-6.x并且我使用ghc-8。这是它不起作用的原因还是我错过了其他的东西?