1
votes

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 error on input '='

What have I done wrong?

2
You should post more than this small snippet (the proceeding line probably has the error).Thomas M. DuBuisson
'Parse error on input' can signify whitespace problems... check you haven't mixed tabs and spaces. But as TomMD points out, we'd need to know more to be sure.stusmith

2 Answers

3
votes

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> 
3
votes

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.