上手haskell沒有不痛苦的!
阿新 • • 發佈:2019-02-13
haskell太怪了,上手很痛苦!
module Main where
import System.Environment(getArgs)
import qualified Data.ByteString as B (readFile, writeFile, map)
main = do
args <- getArgs
case args of
[from, out, direction] ->
if direction == "exe2txt"
then do
s <- B.readFile from
let s1 = B.map (/x->x+1) s
B.writeFile out s1
else if direction == "txt2exe"
then do
s <- B.readFile from
let s1 = B.map (/x->x-1) s
B.writeFile out s1
else do Prelude.putStrLn "usage: hs20101004-1.exe from out direction"
otherwise ->
Prelude.putStrLn "usage: hs20101004-1.exe from out direction"
為什麼case裡面不能case呢?