Reputation: 57
I am trying to create a shift function using let2nat and nat2let functions. This shift function applies a shift factor in the range 0 to 25 to a lower-case letter in the range ’a’ to ’z’. Characters outside this range, such as upper-case letters and punctuation, should be returned unshifted. Make sure your function wraps around at the end of the alphabet.
module Kaan where
import Data.Char
let2nat :: Char -> Int
let2nat x = (ord x) - 97
nat2let :: Int -> Char
m = ['a'..'z']
nat2let x = m !! x
shift :: Int -> Char -> Char
shift x y
| (x + let2nat y <= 25) && (x + let2nat y >= 0) = nat2let x + let2nat y
| (x + let2nat y) > 25 = nat2let (x+let2nat y) `mod` 25
| Otherwise = y
main = do
print $ let2nat 'h'
This is what I am getting : Not in scope: data constructor Otherwise`
Upvotes: 0
Views: 403
Reputation: 10791
The binding is named otherwise
with a lowercase o
. otherwise
is defined to be the same as True
in the Prelude.
Incidentally, anything (at a value-level) that begins with an uppercase character is a data constructor not a normal binding like otherwise
.
Upvotes: 5