<div dir="ltr">The function<div><br></div><div><font face="monospace, monospace"> show :: Show a => a -> String</font></div><div><br></div><div>can be used with</div><div><br></div><div><font face="monospace, monospace"> putStrLn :: String -> IO ()</font></div><div><br></div><div>to get the output on different lines.</div><div><br></div><div>The function</div><div><br></div><div><font face="monospace, monospace"> print :: Show a => a -> IO ()</font></div><div><font face="monospace, monospace"> print = putStr . show</font></div><div><font face="monospace, monospace"> -- convert to string and then print (without newline)</font></div><div><font face="monospace, monospace"><br></font></div>does not put a newline at the end, to get a newline you use<div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"> putStrLn . show $ ...</font></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 24 February 2015 at 15:14, 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Yes, that is one of the books I have to read.<br>
For this exercises chapter 2 and 3 .<br>
<br>
Roelof<br>
<br>
<br>
Francesco Ariis schreef op 24-2-2015 om 10:37:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
off list: try to give a more meaningful title to your posts<br>
(i.e. "cis194 help exercise 2" instead of "how to do this").<br>
It might lead to more answers!<br>
<br>
Also, have you tried "Learn you a haskell for great good"?<div><div class="h5"><br>
<br>
<br>
On Tue, Feb 24, 2015 at 10:28:28AM +0100, Roelof Wobben wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello,<br>
<br>
Im trying to solve exercise 2 of this course :<br>
<a href="http://www.seas.upenn.edu/~cis194/spring13/hw/02-ADTs.pdf" target="_blank">http://www.seas.upenn.edu/~<u></u>cis194/spring13/hw/02-ADTs.pdf</a><br>
<br>
I have this till so far :<br>
<br>
-- | Main entry point to the application.<br>
{-# OPTIONS_GHC -Wall #-}<br>
<br>
module LogAnalysis where<br>
<br>
import Data.Char (isDigit, isLetter)<br>
import Log<br>
<br>
-- | checks if the String is of the format char int<br>
isValid :: String -> Bool<br>
isValid s =<br>
case words s of<br>
[a]:b:_ -> isLetter a && all isDigit b<br>
_ -> False<br>
<br>
-- | Parse the String to make the right logmessage<br>
parse_line :: String -> LogMessage<br>
parse_line s =<br>
case words s of<br>
("I":time:text) -> LogMessage Info (read time)<br>
(unwords text)<br>
("W":time:text) -> LogMessage Warning (read time)<br>
(unwords text)<br>
("E":errorcode:time:text) -> LogMessage (Error (read<br>
errorcode)) (read time) (unwords text)<br>
_ -> Unknown "This is not in the<br>
right format"<br>
<br>
<br>
-- | here the actual function which uses isValid and parse to make<br>
the right log messages<br>
parseMessage :: String -> LogMessage<br>
parseMessage s =<br>
if isValid(s) then parse_line(s) else Unknown "This is not the<br>
right format"<br>
<br>
<br>
parse :: String -> [logMessage]<br>
parse s = parse_line s<br>
<br>
<br>
-- | The main entry point.<br>
main :: IO ()<br>
main = do<br>
print $ show (parseMessage "I 4681 ehci 0xf43d000:15: regista14:<br>
[0xbffff 0xfed nosabled 00-02] Zonseres: brips byted nored)")<br>
print $ show (parseMessage "W 3654 e8] PGTT ASF! 00f00000003.2:<br>
0x000 - 0000: 00009dbfffec00000: Pround/f1743colled")<br>
print $ show (parseMessage "E 47 1034 'What a pity it wouldn't<br>
stay!' sighed the Lory, as soon as it was quite")<br>
<br>
But I do not see how I can get the output of the parse_line into a List.<br>
<br>
Can anyone give me a tip ?<br>
<br>
Roelof<br>
<br>
<br>
<br>
______________________________<u></u>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-<u></u>bin/mailman/listinfo/beginners</a><br>
</blockquote></div></div></blockquote><div class="HOEnZb"><div class="h5">
<br>
______________________________<u></u>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-<u></u>bin/mailman/listinfo/beginners</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>