
On 24 February 2015 at 13:22, Roelof Wobben
Thanks,
I rewrote it like this :
parseMessage :: String -> LogMessage parseMessage s = case words s of ("I":time:text) -> LogMessage Info (read time) (unwords text) ("W":time:text) -> LogMessage Warning (read time) (unwords text) ("E":errorcode:time:text) -> LogMessage Error (read errorcode) (read time) (unwords text) _ -> Unknown "This is not in the right format"
The code looks just fine. Great work. The trouble is with the third case. The error message is fairly instructive. log.hs:19:36: Couldn't match expected type ‘String -> LogMessage’ with actual type ‘LogMessage’ The function ‘LogMessage’ is applied to four arguments, but its type ‘MessageType -> TimeStamp -> String -> LogMessage’ has only three In the expression: LogMessage Error (read errorcode) (read time) (unwords text) In a case alternative: ("E" : errorcode : time : text) -> LogMessage Error (read errorcode) (read time) (unwords text) log.hs:19:47: Couldn't match expected type ‘MessageType’ with actual type ‘Int -> MessageType’ Probable cause: ‘Error’ is applied to too few arguments In the first argument of ‘LogMessage’, namely ‘Error’ In the expression: LogMessage Error (read errorcode) (read time) (unwords text) Long story short, you meant to write LogMessage (Error (read errorcode)) ... instead of LogMessage Error (read errorcode) ... -- Too many arguments to LogMessage (error message 1) -- Too few arguments to Error (error message 2) which is a very common error.