[Haskell-cafe] Rewriting ord (revisited)

2007-09-30 Thread PR Stanley
Hi This was my original version plus some modifications as advised by the list: f c = sum [1 | x - ['\0'..], x c] The following version was sent by a list member: f c = length $ takeWhile (c) ['\0'..] Now, the sender asserted that the first version was much too slow. I'm wondering how the

Re: [Haskell-cafe] Rewriting ord (revisited)

2007-09-30 Thread PR Stanley
The second version looks very neat, certainly, though I am not entirely convinced that it's any more efficient. Still, I may be missing something. The compiler must be one hell of a machine. I wonder if the source code is available to the public. Cheers, Paul At 12:26 30/09/2007, you wrote:

Re: [Haskell-cafe] Rewriting ord (revisited)

2007-09-30 Thread Felipe Almeida Lessa
On 9/30/07, PR Stanley [EMAIL PROTECTED] wrote: Hi This was my original version plus some modifications as advised by the list: f c = sum [1 | x - ['\0'..], x c] The following version was sent by a list member: f c = length $ takeWhile (c) ['\0'..] Now, the sender asserted that the first

[Haskell-cafe] Rewriting filter with foldr

2007-09-30 Thread PR Stanley
Hi filter :: (a - Bool) - [a] - [a] filter f = foldr (\x - \xs - if (f x) then (x:xs) else xs) [] Somehow I feel this could be done more elegantly. What does the list think? Thanks, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] Rewriting ord (revisited)

2007-09-30 Thread Brent Yorgey
The compiler must be one hell of a machine. I wonder if the source code is available to the public. It is, and it is. =) http://hackage.haskell.org/trac/ghc/wiki/Building/GettingTheSources -Brent ___ Haskell-Cafe mailing list

Re: [Haskell-cafe] Rewriting filter with foldr

2007-09-30 Thread Roel van Dijk
Perhaps a list comprehension better shows the intention of the filter function: filter p xs = [x | x - xs, p x] You can literally read that as take all x from xs that satisfy p. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] Rewriting filter with foldr

2007-09-30 Thread Brent Yorgey
On 9/30/07, PR Stanley [EMAIL PROTECTED] wrote: Hi filter :: (a - Bool) - [a] - [a] filter f = foldr (\x - \xs - if (f x) then (x:xs) else xs) [] Somehow I feel this could be done more elegantly. What does the list think? Thanks, Paul Well, note that foldr takes a function of x, which

Re: [Haskell-cafe] Rewriting filter with foldr

2007-09-30 Thread PR Stanley
The question is asking for a new definition of filter using foldr. Sorry, I should have mentioned that before. Cheers, Paul At 14:26 30/09/2007, you wrote: Perhaps a list comprehension better shows the intention of the filter function: filter p xs = [x | x - xs, p x] You can literally read

[Haskell-cafe] Compose

2007-09-30 Thread PR Stanley
Hi sumSquareEven = (sum.map (^2)).filter even I wrote this thinking i was being very clever. The question is asking to spot the error in f = compose [sum, map (^2), filter even] I've only seen [] used in list comprehension and initialisation. I conducted a mini search on compose earlier but to

Re: [Haskell-cafe] Compose

2007-09-30 Thread Felipe Almeida Lessa
On 9/30/07, PR Stanley [EMAIL PROTECTED] wrote: So the question is, does compose as a function or keyword exist in Haskell and if so how can the above code frag be corrected? O and, is compose in any way related to curry and uncurry? You can't write that function in Haskell as the list is

Re: [Haskell-cafe] Rewriting filter with foldr

2007-09-30 Thread PR Stanley
Well, note that foldr takes a function of x, which produces a function of xs. This function of xs either conses x onto it, or leaves it unchanged. We can write this down explicitly by removing the xs parameter and just writing what function should be produced: filter f = foldr (\x - if (f

Re: [Haskell-cafe] Rewriting filter with foldr

2007-09-30 Thread Brandon S. Allbery KF8NH
On Sep 30, 2007, at 11:57 , PR Stanley wrote: Well, note that foldr takes a function of x, which produces a function of xs. This function of xs either conses x onto it, or leaves it unchanged. We can write this down explicitly by removing the xs parameter and just writing what

Re: [Haskell-cafe] Rewriting filter with foldr

2007-09-30 Thread Tim Newsham
filter f = foldr (\x - if (f x) then (x:) else id) [] That's one neat solution but it also raises a few questions for me: foldr :: (a - b - b) - b - [a] - b yet you've managed to squeeze in a function that takes only one argument. How is this possible without GHCI blowing its top? Someone

[Haskell-cafe] Extract source code from literate Haskell (LHS) files

2007-09-30 Thread Peter Verswyvelen
This is of course very easy to do manually, but does a command line tool exist for extracting source code from literate Haskell files? Thanks, Peter ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] Extract source code from literate Haskell (LHS) files

2007-09-30 Thread Brandon S. Allbery KF8NH
On Sep 30, 2007, at 14:39 , Peter Verswyvelen wrote: This is of course very easy to do manually, but does a command line tool exist for extracting source code from literate Haskell files? unlit in the GHC library directory? -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL

Re: [Haskell-cafe] Extract source code from literate Haskell (LHS) files

2007-09-30 Thread Tim Newsham
This is of course very easy to do manually, but does a command line tool exist for extracting source code from literate Haskell files? something like: sed -e '/^[^]/d' -e 's/^//g' foo.lhs foo.hs the first expression deletes lines not starting with . The second expression removes the at

[Haskell-cafe] Re: Extract source code from literate Haskell (LHS) files

2007-09-30 Thread Dominic Steinitz
Peter Verswyvelen bf3 at telenet.be writes: to do manually, but does a command line tool exist for extracting source code from literate Haskell files? Thanks, Peter lhs2tex will do this for you. ___ Haskell-Cafe mailing list

Re: [Haskell-cafe] Yampa question

2007-09-30 Thread Paul L
On 9/29/07, Ryan Ingram [EMAIL PROTECTED] wrote: first bc = SF sf where sf dt ~(b,d) = ((c,d), sfFirst bc') where (c, bc') = runSF bc dt b One question I had was about the implementation of first. Is it important that the pair match be lazy? Or is it safe to make

[Haskell-cafe] The kind of (-)

2007-09-30 Thread jeeva suresh
Hi Guys! According ghci the kind of (-) is ?? - ? - * What do the '??' mean? What is the difference between the '?' and the '*' Cheers -- -Jeeva ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] The kind of (-)

2007-09-30 Thread Stefan O'Rear
On Mon, Oct 01, 2007 at 11:40:20AM +1000, jeeva suresh wrote: Hi Guys! According ghci the kind of (-) is ?? - ? - * What do the '??' mean? What is the difference between the '?' and the '*' It's an implementation detail leaking out. GHC uses a set of special types to represent primitive