[Haskell-beginners] Profiling haskell code

Sayali Kulkarni Sayali.Kulkarni at kpitcummins.com
Sun Dec 7 23:58:24 EST 2008


Hello Brent , 

Thanks for the solution....

Now I have the 2 functions called number and quicksort resp. as follows:


--function "number" which generates an array of numbers, it takes the
ends of the range for numbers as inputs

number s e = if s > e
              then []
              else s : number (s + 1) e

-- this is the same quicksort function that I had used before
quicksort [] = []
quicksort (x : xs) = quicksort larger ++ [x ] ++ quicksort smaller
						where
							smaller = [a | a
<- xs, a <= x ]
							larger = [b | b
<- xs, b > x ]


Now I want the array of numbers generated by the first function "number"
tobe the input of the second function"quicksort".
Then how should I apply the function number to quicksort?

Can you help me out with this?
Also do tel me which is the book that I can refer to for Haskell? 


Regards,
Sayali. 

-----Original Message-----
From: beginners-bounces at haskell.org
[mailto:beginners-bounces at haskell.org] On Behalf Of Brent Yorgey
Sent: Friday, December 05, 2008 6:54 PM
To: beginners at haskell.org
Subject: Re: [Haskell-beginners] Profiling haskell code

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
> 
_______________________________________________
Beginners mailing list
Beginners at haskell.org
http://www.haskell.org/mailman/listinfo/beginners


More information about the Beginners mailing list