<div dir="ltr">From the homework:<div><br></div><div><font face="monospace, monospace">data MessageType = Info</font></div><div><font face="monospace, monospace"> | Warning</font></div><div><font face="monospace, monospace"> | Error Int</font></div><div><font face="monospace, monospace"> deriving (Show, Eq)</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">data LogMessage = LogMessage MessageType TimeStamp String</font></div><div><font face="monospace, monospace"> deriving (Eq, Show)</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">data MaybeLogMessage = ValidM LogMessage -- A valid msg</font></div><div><font face="monospace, monospace"> | InvalidLM String -- Invalid msg</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">parseMessage :: String -> MaybeLogMessage</font></div><div><font face="monospace, monospace">parseMessage = undefined</font></div><div><font face="monospace, monospace"><br></font></div>To implement <font face="monospace, monospace">parseMessage</font>, we consume the string from left to right word-by-word.<div>If the first word is <font face="monospace, monospace">E</font>, then we read the second word as in integer indicating severity and proceed further.</div><div>Info and Warning don't require more information, so the next word will be the timestamp in those cases.</div><div>If the pattern fails anywhere, we return the whole string as an <font face="monospace, monospace">InvalidLM</font>.</div><div><br></div><div>Hope this helps.<br><div><div><br></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 24 February 2015 at 06:37, Richard A. O'Keefe <span dir="ltr"><<a href="mailto:ok@cs.otago.ac.nz" target="_blank">ok@cs.otago.ac.nz</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
On 24/02/2015, at 5:19 am, Roelof Wobben <<a href="mailto:r.wobben@home.nl">r.wobben@home.nl</a>> wrote:<br>
<br>
> I tried it another way more like explained on this page : <a href="http://www.seas.upenn.edu/~cis194/spring13/lectures/02-ADTs.html" target="_blank">http://www.seas.upenn.edu/~cis194/spring13/lectures/02-ADTs.html</a><br>
><br>
> so I tried this :<br>
><br>
> parseMessage :: [Char] -> [Char]<br>
> parseMessage s<br>
> case Errornumber of<br>
> IsDigit Errornumber -> "Geldige string"<br>
> otherwise -> "Ongeldige string"<br>
> where<br>
> Error = s words<br>
> Errornumber = Error(ErrorNumber _ _ )<br>
> Errorcode = Error(_ Errorcode _ )<br>
><br>
> but now I cannot use where :(<br>
<br>
</span>That's not your problem.<br>
<br>
IsDigit ErrorNumber is not a pattern.<br>
<br>
parseMessage s =<br>
if isDigit errorNumber then "Geldige string"<br>
else "Ongelidige string"<br>
where<br>
errorNumber = ???<br>
<br>
is OK.<br>
<br>
Now I cannot make sense of<br>
Error = s words<br>
<br>
identifiers beginning with capital letters are used for<br>
- module names<br>
- type constructors<br>
- data constructors<br>
You want a variable here, so it must begin with a<br>
lower case letter.<br>
<br>
s words treats a string s as a function and applies it<br>
to the function words as argument: s(words). But that<br>
does not type check. You mean words s.<br>
<br>
The result of words s, whatever else it may be, is not<br>
an error.<br>
<br>
Errornumber = Error(ErrorNumber _ _)<br>
<br>
In the form "expr where pattern = expr", the thing after<br>
the equal sign must be an expression. But<br>
Error(ErrorNumber _ _) is not an expression. "_" is a<br>
PATTERN (= I do not care what goes here) but never an<br>
EXPRESSION (because what value would it have?).<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div>Regards</div><div dir="ltr"><div><br></div><div>Sumit Sahrawat</div></div></div></div></div></div></div>
</div>