Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. How can I print the outcome with using main. (Roelof Wobben)
2. Re: How can I print the outcome with using main.
(Joel Williamson)
3. Re: How can I print the outcome with using main. (Roelof Wobben)
4. Re: How can I print the outcome with using main.
(Joel Williamson)
5. Re: How can I print the outcome with using main. (Daniel Bergey)
6. Re: How can I print the outcome with using main. (Roelof Wobben)
7. Re: how to do this ?
(Sumit Sahrawat, Maths & Computing, IIT (BHU))
----------------------------------------------------------------------
Message: 1
Date: Tue, 24 Feb 2015 14:48:11 +0100
From: Roelof Wobben <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] How can I print the outcome with using
main.
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150224/76007ebe/attachment-0001.html>
------------------------------
Message: 2
Date: Tue, 24 Feb 2015 14:10:02 +0000
From: Joel Williamson <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] How can I print the outcome with
using main.
Message-ID:
<cajgxsep6bhjc6as0ybts00ya6usm+cx-wawq1otxmpkeur4...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
testParse returns an IO action. show expects an argument that is in Show.
You will need to bind the result of testParse to a name and ensure that
LogMessage is in Show.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150224/519d3f90/attachment-0001.html>
------------------------------
Message: 3
Date: Tue, 24 Feb 2015 15:16:55 +0100
From: Roelof Wobben <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] How can I print the outcome with
using main.
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150224/c690d057/attachment-0001.html>
------------------------------
Message: 4
Date: Tue, 24 Feb 2015 09:23:34 -0500
From: Joel Williamson <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] How can I print the outcome with
using main.
Message-ID:
<cajgxsep_8zex+0v2_bym8v_hgefuapy9p4dsehbqdeoyenr...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
Has the course covered `do` notation?
On Tue, Feb 24, 2015 at 9:16 AM, Roelof Wobben <[email protected]> wrote:
> Joel Williamson schreef op 24-2-2015 om 15:10:
>
> testParse returns an IO action. show expects an argument that is in Show.
> You will need to bind the result of testParse to a name and ensure that
> LogMessage is in Show.
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
> oke, and how do I do this ?
>
> Roelof
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
------------------------------
Message: 5
Date: Tue, 24 Feb 2015 14:44:55 +0000
From: Daniel Bergey <[email protected]>
To: Roelof Wobben <[email protected]>, The Haskell-Beginners Mailing
List - Discussion of primarily beginner-level topics related to
Haskell <[email protected]>
Subject: Re: [Haskell-beginners] How can I print the outcome with
using main.
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
Try:
| main :: IO ()
| main = do
| msgs <- testParse parse 10 "error.log"
| print msgs
Your plan is good. GHCi handles IO values specially, for convenience,
which blurs the distinction between values which can be fed to `print`
directly, and those in IO, which need to be bound as above.
On 2015-02-24 at 13:48, Roelof Wobben <[email protected]> wrote:
> Hello,
>
> According to the manual of the CIS 194 course I have to do this in GHCI :?
> testParse parse 10 "error.log"
> This to test my code.
>
> Now my problem is that I cannot use GHCI because I use Fpcomplete.
> So I thought I will use main for this :
>
> So I tried? this :
>
> main :: IO ()
> main = do
> ?? print? $ testParse parse 10 "error.log"
>
> but then I see this error message :
>
> src/LogAnalysis.hs@39:4-39:9
> No instance for (Show (IO [LogMessage])) arising from a use of
> print
> ? In the expression: print In a stmt of a 'do' block: print $ testParse parse
> 10 "error.log" In the expression: do { print $
> testParse parse 10 "error.log" }
>
> The testparse function looks like this :
>
> -- | @testParse p n f@ tests the log file parser @p@ by running it
> --?? on the first @n@ lines of file @f@.
> testParse :: (String -> [LogMessage])
> ????????? -> Int
> ????????? -> FilePath
> ????????? -> IO [LogMessage]
> testParse parse n file = take n . parse <$> readFile file
>
> Roelof
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
Message: 6
Date: Tue, 24 Feb 2015 16:36:09 +0100
From: Roelof Wobben <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] How can I print the outcome with
using main.
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8; format=flowed
Daniel Bergey schreef op 24-2-2015 om 15:44:
> main :: IO ()
> | main = do
> | msgs <- testParse parse 10 "error.log"
> | print msgs
Thanks,
Now Im busy reading how to make a tree withe recursion for the next
exercise.
Roelof
------------------------------
Message: 7
Date: Tue, 24 Feb 2015 21:39:07 +0530
From: "Sumit Sahrawat, Maths & Computing, IIT (BHU)"
<[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] how to do this ?
Message-ID:
<cajbew8ogcihb-pe9cmwgltmpg-xx92uq_rlogdcuq__7nao...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
The function
show :: Show a => a -> String
can be used with
putStrLn :: String -> IO ()
to get the output on different lines.
The function
print :: Show a => a -> IO ()
print = putStr . show
-- convert to string and then print (without newline)
does not put a newline at the end, to get a newline you use
putStrLn . show $ ...
On 24 February 2015 at 15:14, Roelof Wobben <[email protected]> wrote:
> Yes, that is one of the books I have to read.
> For this exercises chapter 2 and 3 .
>
> Roelof
>
>
> Francesco Ariis schreef op 24-2-2015 om 10:37:
>
>> off list: try to give a more meaningful title to your posts
>> (i.e. "cis194 help exercise 2" instead of "how to do this").
>> It might lead to more answers!
>>
>> Also, have you tried "Learn you a haskell for great good"?
>>
>>
>>
>> On Tue, Feb 24, 2015 at 10:28:28AM +0100, Roelof Wobben wrote:
>>
>>> Hello,
>>>
>>> Im trying to solve exercise 2 of this course :
>>> http://www.seas.upenn.edu/~cis194/spring13/hw/02-ADTs.pdf
>>>
>>> I have this till so far :
>>>
>>> -- | Main entry point to the application.
>>> {-# OPTIONS_GHC -Wall #-}
>>>
>>> module LogAnalysis where
>>>
>>> import Data.Char (isDigit, isLetter)
>>> import Log
>>>
>>> -- | checks if the String is of the format char int
>>> isValid :: String -> Bool
>>> isValid s =
>>> case words s of
>>> [a]:b:_ -> isLetter a && all isDigit b
>>> _ -> False
>>>
>>> -- | Parse the String to make the right logmessage
>>> parse_line :: String -> LogMessage
>>> parse_line 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"
>>>
>>>
>>> -- | here the actual function which uses isValid and parse to make
>>> the right log messages
>>> parseMessage :: String -> LogMessage
>>> parseMessage s =
>>> if isValid(s) then parse_line(s) else Unknown "This is not the
>>> right format"
>>>
>>>
>>> parse :: String -> [logMessage]
>>> parse s = parse_line s
>>>
>>>
>>> -- | The main entry point.
>>> main :: IO ()
>>> main = do
>>> print $ show (parseMessage "I 4681 ehci 0xf43d000:15: regista14:
>>> [0xbffff 0xfed nosabled 00-02] Zonseres: brips byted nored)")
>>> print $ show (parseMessage "W 3654 e8] PGTT ASF! 00f00000003.2:
>>> 0x000 - 0000: 00009dbfffec00000: Pround/f1743colled")
>>> print $ show (parseMessage "E 47 1034 'What a pity it wouldn't
>>> stay!' sighed the Lory, as soon as it was quite")
>>>
>>> But I do not see how I can get the output of the parse_line into a List.
>>>
>>> Can anyone give me a tip ?
>>>
>>> Roelof
>>>
>>>
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> [email protected]
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>>
>>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
--
Regards
Sumit Sahrawat
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150224/2ede4068/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 80, Issue 65
*****************************************