我在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