quickCheck错误出现分段错误:11

时间:2013-09-09 08:09:05

标签: haskell quickcheck

我正在研究“Haskell - 函数式编程技巧”,并且遇到了一个非常奇怪的问题:

我定义了以下两个函数:

averageThree :: Integer -> Integer -> Integer -> Float
averageThree a b c = (fromIntegral (a + b + c)) / 3

howManyAboveAverage :: Integer -> Integer -> Integer -> Integer

howManyAboveAverage a b c
    | (a == b) && (b == c) && (a == c) = 0
    | (fromIntegral a > (averageThree a b c) && (fromIntegral b > (averageThree a b c) || fromIntegral c > (averageThree a b c))) || (fromIntegral b > (averageThree a b c) && fromIntegral c > (averageThree a b c))  = 2
    | otherwise = 1

这似乎都产生了预期的结果。然后我定义了以下quickCheck属性:

prop_averageThree1, prop_averageThree2, prop_averageThree3, prop_howManyAboveAverage :: Integer -> Integer -> Integer -> Bool

prop_averageThree1 a b c = (((averageThree a b c) * (fromIntegral 3)) == (fromIntegral (a + b + c)))
prop_averageThree2 a b c = (fromIntegral a >= averageThree a b c) || (fromIntegral b >= averageThree a b c) || (fromIntegral c >= averageThree a b c)
prop_averageThree3 a b c = (fromIntegral a <= averageThree a b c) || (fromIntegral b <= averageThree a b c) || (fromIntegral c <= averageThree a b c)
prop_howManyAboveAverage a b c = (0 <= howManyAboveAverage a b c) && (2 >= howManyAboveAverage a b c)

使用quickCheck prop_name运行时所有这些属性都会生成:

Segmentation fault: 11

我的模块定义如下:

module Chapter3 where
import Data.Char
import Test.QuickCheck

导致此错误消息的原因是什么?

0 个答案:

没有答案