What's the problem with code.
My Haskell platform is new . And I have tried to adjust the formats for many times. But it didn't work all the time.
import Data.Char
import Data.List
encode :: Int -> String -> String
encode shift msg =
let ords = map ord msg
shifted = map (+ shift) ords
in map chr shifted
The result is always like this
Prelude> :r
Ok, no modules loaded.
Prelude> :type encode
<interactive>:1:1: error: Variable not in scope: encode
When I load my files, it shows
Prelude> :l H2-2.hs
[1 of 1] Compiling Main ( H2-2.hs, interpreted )
H2-2.hs:56:3: error: parse error on input ‘shifted’
|
56 | shifted = map (+ shift) ords
| ^^^^^^^
Failed, no modules loaded.
ghciwithghci myfile.hs?Prelude> :r Ok, no modules loaded- that makes it looks like you haven't actually loaded your module. You need to do:l <module_name>first (then you don't need:runtil you've made modifications and want to reload it).encode shift msg = map (chr. (+ shift) . ord) msg; in general,map f (map g xs) == map (f . g) xs.