haskell - parse error in pattern -


count []       = 0 count (b:xs) = c + count xs   c = case b of           (b==a) -> 1           (b/=a) -> 0 

ghci gives error "parse error in pattern: b == a"

i know why parse error occurs.

thank you.

a == b not pattern, it's expression. other answer says, work:

case == b of   true  -> 1   false -> 0 

but can written more as

if == b 1 else 0 

perhaps you're thinking pattern guards?

case of   junk | == b -> 1        | /= b -> 0 

in general, haskell offers many different ways conditional branching, can confusing work out 1 need. patterns when want decide based on constructor present, or want extract 1 of constructor's fields variable something. comparing values, want if-expression instead.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -