EDIT: I shouldn't be coding when this tired. I was compiling a different copy of the program than I was running. Sorry for wasting your time.
I have the following code to make a single argument optional in my program's startup.
main = do
args <- getArgs
handleArgs args
handleArgs :: [String] -> IO ()
handleArgs (server:nick:channel:[]) = IRC.startIRC server 6667 nick channel
handleArgs (server:port:nick:channel:[]) = IRC.startIRC server (read port :: Int) nick channel
handleArgs _ = putStrLn "Incorrect arguments given."
If I run it like ./program irc.freenode.net 6667 somenick #somechannel
, it runs. However, if I run it like ./program irc.freenode.net somenick #somechannel
, which should make args be a list "irc.freenode.net":"somenick":"#somechannel":[]
if I understand it correctly,
it gives a pattern match error pointing to the args <- getArgs
line when I try to run it after compiling with ghc.
More precisely, the error is:
mbot: user error (Pattern match failure in do expression at core.hs:9:4-32)