[Haskell-beginners] Profiling haskell code
Brent Yorgey
byorgey at seas.upenn.edu
Fri Dec 5 08:24:26 EST 2008
To get the output of one function to be the input to another, you just
apply one to the other. For example:
-- This function generates a list
foo :: Int -> [Int]
foo n = [1..n]
-- This function expects a list as input
bar :: [Int] -> Int
bar = sum . filter (>5)
-- Use the output of foo as input to bar
main = print $ bar (foo 20)
Are you asking about something more than this?
-Brent
On Thu, Dec 04, 2008 at 05:42:42PM +0530, Sayali Kulkarni wrote:
> Hey thanks Brent. This helped.
>
> I have one more question now.
>
> Consider I have two functions
> 1. gives me a range of numbers in an array.
> 2. has to get an array input for further process.
>
> Then how can I get the array generated by the first function tobe the
> input of the second function?
>
> Regards,
> Sayali
>
> -----Original Message-----
> From: Brent Yorgey [mailto:byorgey at seas.upenn.edu]
> Sent: Tuesday, November 18, 2008 5:47 PM
> To: Sayali Kulkarni
> Subject: Re: [Haskell-beginners] Profiling haskell code
>
> > I have just given it any random input array to be sorted.
> > The commands that I had sent earlier were tried on Cygwin...
> > (
> > > > $ ghc --make Project.hs -prof -auto-all
> > > >
> > > >
> > > > $ Project +RTS -p
> > > > )
>
> This ought to work fine. Just a note, to do any reasonable profiling
> you will need to give it a *much* larger list to sort. Otherwise it
> will
> execute so quickly that the timing data you get will be meaningless.
>
> >
> > Also can you tell me any other method for profiling the code that you
> > know?
>
> If you just want to see how long it takes to evaluate certain
> expressions, you can type ':set +s' in ghci; from then on after every
> expression you type it will tell you how long it took to evaluate and
> how much memory was used.
>
> -Brent
>
More information about the Beginners
mailing list