0
當我只寫main = do ...
塊時,它完美的工作。當我把只有stories = do...
塊它也可以。也許有一個縮進問題。解析錯誤輸入「=」haskell錯誤
下面是代碼:
stories = do
let str0 = "There once was "
str1 <- ["a princess ", "a cat ", "a little boy "]
let str2 = "who lived in "
return ( str0 ++ str1 )
main = do
let len = length stories
putStrLn ("Enter a number from 0 to " ++ show (len - 1))
n <- readLn
putStrLn ""
putStrLn (stories !! n)
有什麼不對呢?
只是爲了確認,在OP的問題是,他們基本上是試圖定義'了'do'塊內main'。 – BalinKingOfMoria