I'm new to haskell and cannot work out what is wrong with my code. I keep getting a variable out of scope error.
Here is my code that i load into GHCi using :load
validLength :: String -> Bool
validLength xs | length xs == 26 = True
| otherwise = False
I then type validLength aa
which should return false but i'm getting an error.
*Main> validLength aa
<interactive>:1:13: error: Variable not in scope: aa :: String
Identifiers are not strings. (This is by no means special to Haskell, it's the same in most other languages.) So, when you give aa
as the argument, GHC interprets it as the name of some variable. But, well, there is no variable with that name, at least not in scope, thus the error.
If you want to pass actually the string consisting of two a
characters, then you should use a string literal. A string literal is simply a string in double quotes (again, that's the same way it is in many other programming languages).
*Main> validLength "aa"
False
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With