我在这段代码中有一个问题:
module Blueprint where
data Colour = Blue | Green | Red
deriving ( Eq, Show )
data Car = Car { wheels :: Integer
, colour :: Colour
}
deriving ( Eq, Show )
data Property = Colour_Is Colour
| Wheels Ordering Integer
| And Property Property
| Not Property
| Or Property Property
deriving Show
check :: Property -> Car -> Bool
check prop car = case prop of
Colour_Is col -> col == colour car
Wheels ord num -> case ord of
LT -> num > wheels car
EQ -> num == wheels car
And l r -> check l car && check r car
Not p -> not check p car
Or x y -> check x car || check y car
cars = [ Car { wheels = 4, colour = Red }
, Car { wheels = 2, colour = Blue }
, Car { wheels = 14, colour = Green }
, Car { wheels = 4, colour = Green }
, Car { wheels = 2, colour = Red }
]
prop1 :: Property
prop1 = And (Wheels EQ 14) (Colour_Is Green)
test :: Bool
test = and
[ check ( Wheels EQ 4 ) ( cars !! 0 )
, check ( Wheels LT 3 ) ( cars !! 1 )
, check ( And ( Wheels EQ 14 ) ( Colour_Is Green )) ( cars !! 2 )
, check ( Not ( Colour_Is Red ) ) ( cars !! 3 )
, filter ( check prop1 ) cars == take 3 cars
]
我构建了检查函数并正确实现了 Colour_Is,And,Not 和 Wheels,但是当我添加 Or 函数时:
( Or x y -> check x car || check y car )
我从 ghci 收到此错误:
D:\My_data\hs\strategy.hs:26:16:输入“->”解析错误失败,加载模块:无。
我是 Haskell 的新手。我的错误在哪里?