import Data.ByteString as B
import Data.ByteString.Internal as I
import Data.Bits
main = do input <- getLine
let bs = B.pack input
let intermediatebs = unfoldrN ((B.length bs)*2) unfld 0
where unfld i
|Prelude.rem i 2 == 0 = Just (top4 $ B.index bs (i/2) , i+1)
|otherwise = Just (bottom4 $ B.index bs (i/2) , i+1)
top4bits x = shiftR x 4
bottom4bits x = x .&. 0x0F
top4 x = convertASCIIword8 $ top4bits x
bottom4 x = convertASCIIword8 $ bottom4bits x
convertASCIIword8 x
|x <= 9 = I.c2w '0' + x
|otherwise = I.c2w 'A' + (x-10)
let outputbs = B.map I.w2c $ intermediatebs
in do putStrLn (outputbs)
我得到這個編譯錯誤 最後一條語句在「做」結構必須是一個表達式: 讓intermediatebs = unfoldrN((B.length bs)* 2)unfld 0在「做」結構的最後一條語句必須是一個表達式:有沒有壓痕錯誤
看起來你有三個'let'但只有一個'in'。這不會很好結束。那麼'let'和'where'綁定的混合是什麼? –
@HenningMakholm頭兩個'let's在'do'-block內,不需要'in'。 – sepp2k
這裏的主要問題是(a)縮進錯誤(b)使用哪裏可能會更清楚,但主要和最明顯(c)試圖在一個主要內容中做所有事情。它很難調試。請把你的代碼重新編寫成單獨的函數,直到你可以寫出main = fmap myProcessingFunction getLine >> = putStrLn – AndrewC