0

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`

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.