<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 24 February 2015 at 13:22, Roelof Wobben <span dir="ltr"><<a href="mailto:r.wobben@home.nl" target="_blank">r.wobben@home.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Thanks,<br>
<br>
I rewrote it like this :<br>
<br>
parseMessage :: String -> LogMessage<br>
parseMessage s =<br>
case words s of<br>
("I":time:text) -> LogMessage Info (read time) (unwords text)<br>
("W":time:text) -> LogMessage Warning (read time) (unwords text)<br>
("E":errorcode:time:text) -> LogMessage Error (read errorcode) (read time) (unwords text)<br>
_ -> Unknown "This is not in the right format"<br></blockquote><div><br></div><div>The code looks just fine. Great work.</div><div>The trouble is with the third case. The error message is fairly instructive.</div><div><br></div><div><div><font face="monospace, monospace">log.hs:19:36:</font></div><div><font face="monospace, monospace"> Couldn't match expected type ‘String -> LogMessage’</font></div><div><font face="monospace, monospace"> with actual type ‘LogMessage’</font></div><div><font face="monospace, monospace"> The function ‘LogMessage’ is applied to four arguments,</font></div><div><font face="monospace, monospace"> but its type ‘MessageType -> TimeStamp -> String -> LogMessage’</font></div><div><font face="monospace, monospace"> has only three</font></div><div><font face="monospace, monospace"> In the expression:</font></div><div><font face="monospace, monospace"> LogMessage Error (read errorcode) (read time) (unwords text)</font></div><div><font face="monospace, monospace"> In a case alternative:</font></div><div><font face="monospace, monospace"> ("E" : errorcode : time : text)</font></div><div><font face="monospace, monospace"> -> LogMessage Error (read errorcode) (read time) (unwords text)</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">log.hs:19:47:</font></div><div><font face="monospace, monospace"> Couldn't match expected type ‘MessageType’</font></div><div><font face="monospace, monospace"> with actual type ‘Int -> MessageType’</font></div><div><font face="monospace, monospace"> Probable cause: ‘Error’ is applied to too few arguments</font></div><div><font face="monospace, monospace"> In the first argument of ‘LogMessage’, namely ‘Error’</font></div><div><font face="monospace, monospace"> In the expression:</font></div><div><font face="monospace, monospace"> LogMessage Error (read errorcode) (read time) (unwords text)</font></div></div><div><br></div><div>Long story short, you meant to write</div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"> LogMessage (Error (read errorcode)) ...</font></div><div><font face="monospace, monospace"><br></font></div>instead of</div><div class="gmail_quote"><br><div><font face="monospace, monospace"> LogMessage Error (read errorcode) ... -- Too many arguments to LogMessage (error message 1)</font></div><div><font face="monospace, monospace"> -- Too few arguments to Error (error message 2)</font></div><div><br></div><div>which is a very common error.</div></div>
</div></div>