我在Haskell中有這樣的代碼。let在Haskell中的用法
import Data.List
main = do
putStrLn $ "\nVerify if Exists in a String"
let wordlist = ["monad", "monoid", "Galois", "ghc", "SPJ"]
let tweet = "This is an example tweet talking about SPJ interviewing with Galois"
print $ map (flip isInfixOf tweet) wordlist
沒有let
,我有這樣的錯誤消息:10_things.hs:16:14: parse error on input ‘=’
。
這是另一種正常工作的代碼。
import Data.List
wordlist = ["monad", "monoid", "Galois", "ghc", "SPJ"]
tweet = "This is an example tweet talking about SPJ interviewing with Galois"
main = do
putStrLn $ "\nVerify if Exists in a String"
print $ map (flip isInfixOf tweet) wordlist
在這種情況下,我有錯誤parse error (possibly incorrect indentation or mismatched brackets)
與讓。 我的問題是何時何時不在Haskell中使用let
?
'do'符號並不像它看起來那麼容易:HTTP:// en.wikibooks.org/wiki/Haskell/do_notation + http://book.realworldhaskell.org/read/io.html#io.bind – zerkms 2015-02-10 02:11:38