|||caesar :: Int -> String -> String|
|||caesar k = map f|
|||| inRange ('A', 'Z') c = chr $ ord 'A'|
|||+ (ord c - ord 'A' + k) `mod` 26|
|||| otherwise = c|
In this example, we recreate the Caesar implementation. You can ignore the slew of import statements for now. They will all be used during this chapter, so we’re putting them in place so we don’t have to worry about them later.
Our Haskell implementation starts with a type signature. It accepts an Int and a String, and returns a String. The function maps over all the characters in the message and applies the shift as long as the character is in the range of uppercase ...