So I am getting the error:
error:
parse error on input `|'
| x == 'a' = True
The code itself is:
module SubstitutionCiphers where
import AssignmentHelp.Cipher
validateCipher :: Cipher -> Boolean
validateCipher "" = False
validateCipher (x:xs)
| x == 'a' = True
| otherwise = validateCipher xs
I tried alternating the indentation in various different ways but nothing seems to work. I guess it is still an indentation problem, but I have no clue how to fix it.
When you indent the first line of the definition, the parser (in this context) thinks you are continuing the previous line, as if you had written
validateCipher :: Cipher -> Bool validateCipher "" = False -- etc
This becomes obvious with a simpler definition
validateCipher :: String -> Bool
validateCipher _ = True
because the parser is able to accept this. The resulting placement of the type signature, though, is invalid.
<interactive>:11:1: error:
Illegal type signature: ‘String -> Bool validateCipher _’
Type signatures are only allowed in patterns with ScopedTypeVariables
(I suspect that, if the ScopedTypeVariables
extension did not exist, you would get a more generic parser error on the =
. )
In your actual definition, the parser continues trying to parse a type signature, and doesn't run into a syntactic problem until it sees the |
.
The solution is to not indent the definition:
validateCipher :: Cipher -> Bool
validateCipher "" = False
validateCipher (x:xs)
| x == 'a' = True
| otherwise = validateCipher xs
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments