import Data.Char
import Prelude
import System.IO
encode :: Char -> Int
encode x = ord x - ord 'A'
decode :: Int -> Char
decode x = chr (x + ord 'A')
shift :: (Int -> Int -> Int) -> Int -> Char -> Char
shift f x ch = decode $ f (encode ch) x `mod` 26
rightShift :: Int -> Char -> Char
rightShift = shift (-)
leftShift :: Int -> Char -> Char
leftShift = shift (-)
encodeString :: String -> [Int]
encodeString str = map encode str
vignereString :: String -> String -> String
vignereString secret plain = take len $ cycle secret
where len = length $ concat
vignereCode :: String -> String -> [Int]
vignereCode secret plain = encodeString $ vignereString
encrypt :: String -> String -> String
encrypt secret plain =
zipWith rightShift code plainNoSpace
where code = vignereCode secret plain
plainNoSpace = concat $ words plain
decrypt :: String -> String -> String
decrypt secret cipher = zipWith leftShift code cipherNoSpace
where code = vignereCode secret cipher
cipherNoSpace = concat $ words cipher
error message: main.hs:28:43: error:
* Couldn't match type `String -> String -> String' with `[Char]'
Expected type: String
Actual type: String -> String -> String
* Probable cause: `vignereString' is applied to too few arguments
In the second argument of `($)', namely `vignereString'
In the expression: encodeString $ vignereString
In an equation for `vignereCode':
vignereCode secret plain = encodeString $ vignereString
|
28 | vignereCode secret plain = encodeString $ vignereString
| ^^^^^^^^^^^^^
exit status 1
In
vignereCodeyou are not passing any argument tovignereString. I think you want to composeencodeStringandvignereStringinstead to apply the former to the latter.