Haskell 产生如此多错误报告的简单代码
我正试着做上述的MannWhitney-U测试。以下是我的代码:Haskell 产生如此多错误报告的简单代码,haskell,statistics,Haskell,Statistics,我正试着做上述的MannWhitney-U测试。以下是我的代码: import Data.Vector as V import Data.Vector.Unboxed as VU import Statistics.Test.MannWhitneyU sampleA = [1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4] sampleB = [2.0, 4.0, 5.0, 5.0, 3.0, 4.0, 5.0, 6] main = do putStrLn
import Data.Vector as V
import Data.Vector.Unboxed as VU
import Statistics.Test.MannWhitneyU
sampleA = [1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4]
sampleB = [2.0, 4.0, 5.0, 5.0, 3.0, 4.0, 5.0, 6]
main = do
putStrLn "\nResult of mannWhitneyUtest: "
print (mannWhitneyUtest SamplesDiffer 0.05 (VU.fromList sampleA) (VU.fromList sampleB) )
但是,错误比上述代码长得多:
[1 of 1] Compiling Main ( rnmann.hs, rnmann.o )
rnmann.hs:6:12: error:
• Ambiguous type variable ‘t0’ arising from the literal ‘1.0’
prevents the constraint ‘(Fractional t0)’ from being solved.
Relevant bindings include sampleA :: [t0] (bound at rnmann.hs:6:1)
Probable fix: use a type annotation to specify what ‘t0’ should be.
These potential instances exist:
instance Fractional Double -- Defined in ‘GHC.Float’
instance Fractional Float -- Defined in ‘GHC.Float’
...plus four instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In the expression: 1.0
In the expression: [1.0, 2.0, 3.0, 4.0, ....]
In an equation for ‘sampleA’: sampleA = [1.0, 2.0, 3.0, ....]
rnmann.hs:6:47: error:
• Ambiguous type variable ‘t0’ arising from the literal ‘4’
prevents the constraint ‘(Num t0)’ from being solved.
Relevant bindings include sampleA :: [t0] (bound at rnmann.hs:6:1)
Probable fix: use a type annotation to specify what ‘t0’ 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
...plus 13 instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In the expression: 4
In the expression: [1.0, 2.0, 3.0, 4.0, ....]
In an equation for ‘sampleA’: sampleA = [1.0, 2.0, 3.0, ....]
rnmann.hs:7:12: error:
• Ambiguous type variable ‘t0’ arising from the literal ‘2.0’
prevents the constraint ‘(Fractional t0)’ from being solved.
Relevant bindings include sampleB :: [t0] (bound at rnmann.hs:7:1)
Probable fix: use a type annotation to specify what ‘t0’ should be.
These potential instances exist:
instance Fractional Double -- Defined in ‘GHC.Float’
instance Fractional Float -- Defined in ‘GHC.Float’
...plus four instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In the expression: 2.0
In the expression: [2.0, 4.0, 5.0, 5.0, ....]
In an equation for ‘sampleB’: sampleB = [2.0, 4.0, 5.0, ....]
rnmann.hs:7:47: error:
• Ambiguous type variable ‘t0’ arising from the literal ‘6’
prevents the constraint ‘(Num t0)’ from being solved.
Relevant bindings include sampleB :: [t0] (bound at rnmann.hs:7:1)
Probable fix: use a type annotation to specify what ‘t0’ 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
...plus 13 instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In the expression: 6
In the expression: [2.0, 4.0, 5.0, 5.0, ....]
In an equation for ‘sampleB’: sampleB = [2.0, 4.0, 5.0, ....]
rnmann.hs:11:16: error:
• Ambiguous type variable ‘t0’ arising from a use of ‘mannWhitneyUtest’
prevents the constraint ‘(Ord t0)’ from being solved.
Probable fix: use a type annotation to specify what ‘t0’ should be.
These potential instances exist:
instance Ord Ordering -- Defined in ‘GHC.Classes’
instance Ord Integer
-- Defined in ‘integer-gmp-1.0.0.1:GHC.Integer.Type’
instance Ord PositionTest -- Defined in ‘Statistics.Test.Types’
...plus 26 others
...plus 25 instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In the first argument of ‘print’, namely
‘(mannWhitneyUtest
SamplesDiffer 0.05 (VU.fromList sampleA) (VU.fromList sampleB))’
In a stmt of a 'do' block:
print
(mannWhitneyUtest
SamplesDiffer 0.05 (VU.fromList sampleA) (VU.fromList sampleB))
In the expression:
do { putStrLn
"\n\
\Result of mannWhitneyUtest: ";
print
(mannWhitneyUtest
SamplesDiffer 0.05 (VU.fromList sampleA) (VU.fromList sampleB)) }
rnmann.hs:11:47: error:
• No instance for (Fractional (Statistics.Types.PValue Double))
arising from the literal ‘0.05’
• In the second argument of ‘mannWhitneyUtest’, namely ‘0.05’
In the first argument of ‘print’, namely
‘(mannWhitneyUtest
SamplesDiffer 0.05 (VU.fromList sampleA) (VU.fromList sampleB))’
In a stmt of a 'do' block:
print
(mannWhitneyUtest
SamplesDiffer 0.05 (VU.fromList sampleA) (VU.fromList sampleB))
rnmann.hs:11:75: error:
• Ambiguous type variable ‘t0’ arising from a use of ‘VU.fromList’
prevents the constraint ‘(Unbox t0)’ from being solved.
Probable fix: use a type annotation to specify what ‘t0’ should be.
These potential instances exist:
instance Unbox () -- Defined in ‘Data.Vector.Unboxed.Base’
instance (Unbox a, Unbox b) => Unbox (a, b)
-- Defined in ‘Data.Vector.Unboxed.Base’
instance (Unbox a, Unbox b, Unbox c) => Unbox (a, b, c)
-- Defined in ‘Data.Vector.Unboxed.Base’
...plus 9 others
...plus 16 instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In the fourth argument of ‘mannWhitneyUtest’, namely
‘(VU.fromList sampleB)’
In the first argument of ‘print’, namely
‘(mannWhitneyUtest
SamplesDiffer 0.05 (VU.fromList sampleA) (VU.fromList sampleB))’
In a stmt of a 'do' block:
print
(mannWhitneyUtest
SamplesDiffer 0.05 (VU.fromList sampleA) (VU.fromList sampleB))
我认为关键问题是如何将0.05作为Pvalue
感谢您的帮助。以下是错误报告中与此超级相关的部分 由文本“4”产生的不明确类型变量“t0” 可能的修复:使用类型注释指定“t0”应该是什么 它是一个
Int
,Double
,Float
?编译器无法分辨,因为它是不明确的
添加类型签名应该可以解决问题
sampleA :: [Double]
您不能使用
0.05
,因为您可以使用来构造PValue
:
import Statistics.Types(mkPValue)
main = do
putStrLn "\nResult of mannWhitneyUtest: "
print $
mannWhitneyUtest SamplesDiffer (mkPValue 0.05) (VU.fromList sampleA) (VU.fromList sampleB)
这不是输出,这些是编译错误。是的,我指的是错误报告。在
samreak
上的显式类型签名可以帮助您找到此错误。根据经验:当类型错误消息令人困惑时,添加更多类型签名。它通常不会解决问题,但会改善错误消息。在我之前的示例中,我从未需要这样做。
Result of mannWhitneyUtest:
Just Significant