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:[hidden email]] 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 |
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:[hidden email]] > 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 > |
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: [hidden email] [mailto:[hidden email]] On Behalf Of Brent Yorgey Sent: Friday, December 05, 2008 6:54 PM To: [hidden email] 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:[hidden email]] > 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 > > 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 [hidden email] http://www.haskell.org/mailman/listinfo/beginners |
> --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 Just an aside: instead of 'number s e' you can just write [s..e] . > 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? Like this: quicksort (number 3 50) You always apply a function f to an input x like this: f x . So the above code says to apply quicksort to the input (number 3 50), which is of course the output from applying number to the inputs 3 and 50. The parentheses are needed since without them, 'quicksort number 3 50' tries to give three inputs to quicksort, namely 'number' '3' and '50', which is obviously wrong. > Also do tel me which is the book that I can refer to for Haskell? There are many available books and online tutorials. Some ones I might recommend for you: The Haskell wikibook -- http://en.wikibooks.org/wiki/Haskell Yet Another Haskell Tutorial -- http://en.wikibooks.org/wiki/Haskell/YAHT Learn You a Haskell -- www.learnyouahaskell.com Programming in Haskell -- http://www.amazon.com/Programming-Haskell-Graham-Hutton/dp/0521692695 There are many other books and tutorials as well -- e.g., the Gentle Introduction to Haskell, the Haskell School of Expression, and Real World Haskell (just google them if you are interested). Check these out and hopefully you can find something that you like. -Brent > > > Regards, > Sayali. > > -----Original Message----- > From: [hidden email] > [mailto:[hidden email]] On Behalf Of Brent Yorgey > Sent: Friday, December 05, 2008 6:54 PM > To: [hidden email] > 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:[hidden email]] > > 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 > [hidden email] > http://www.haskell.org/mailman/listinfo/beginners > |
Free forum by Nabble | Edit this page |