开发者

Syntax error: parse error on input ' -> ' ) [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I have a problem in this code:

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
    ]

I built the check function and implemented Colour_Is,And,Not and Wheels correctly, but when I add the Or function:

( Or x y -> check x car || check y car )

I'm getting this error from ghci :

D:\开发者_如何学运维My_data\hs\strategy.hs:26:16: parse error on input `->' Failed, modules loaded: none.

I'm new to Haskell. Where is my mistake?


Your parse error is probably due to incorrect indentation, but that error doesn't exist with Dhaivat's reformatting of your question.

Further, you needed parens around the argument for not:

  Not p -> not check p car
-->
  Not p -> not (check p car)

In addition to properly formatting your question, next time please pick a sensible title. The title of "Haskell doesn't work" is a) wrong b) uninformative c) not conductive to getting an answer from people who like Haskell. It's still a small enough community that may people with a personal investment in the Language (people who've worked on the language spec and core libraries) are actually part of the language's social scene.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜