2

我正在研究“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

是什么导致此错误消息?

4

0 回答 0