开发者

Error compiling Haskell

I'm brand new to Haskell and have very little idea what I'm doing. I've been reading a few tutorials and am now attempting to step through a Roll your own IRC bot example.

I get a compilation error from ghc on:

clean     = drop 1 . dropWhile (/= ':') . drop 1

The error is:

irc.hs:34:11: parse er开发者_运维百科ror on input '='

What have I done wrong?


This is the code you are working with, yes?

listen :: Handle -> IO ()
listen h = forever $ do
    t <- hGetLine h
    let s = init t
    if ping s then pong s else eval h (clean s)
    putStrLn s
  where
    forever a = a >> forever a

    clean     = drop 1 . dropWhile (/= ':') . drop 1

    ping x    = "PING :" `isPrefixOf` x
    pong x    = write h "PONG" (':' : drop 6 x)

Ensure your definition of clean is indented by the same amount as the preceeding definition of forever. It is on the "Roll your own IRC bot" page, but presumably isn't in the copy you're trying to compile.


This is actually fine. If you're running this in GHCi/Hugs, you're in IO, so you need a let.

Prelude> let clean     = drop 1 . dropWhile (/= ':') . drop 1
Prelude> :t clean
clean :: [Char] -> [Char]
Prelude> 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜