Re: [Haskell-cafe] Is take behaving correctly?

2007-09-13 Thread rahn
pref_eq k xs ys = take k xs == take k ys This seems to be a straightforward implementation with good properties. Actually, no, at least not if implemented naively. I choosed this example, since I stumbled on this question last week. Reputable mathematicians doing combinatorics on

Re: [Haskell-cafe] Is take behaving correctly?

2007-09-12 Thread rahn
take 1000 [1..3] still yields [1,2,3] You can think about take n as: Take as much as possible, but at most n elements. This behavior has some nice properties as turned out by others, but there are some pitfalls. We have length . take n /= const n in general, instead only length . take

Re: [Haskell-cafe] Is take behaving correctly?

2007-09-12 Thread Conor McBride
Hi folks On 12 Sep 2007, at 00:38, Brent Yorgey wrote: On 9/11/07, PR Stanley [EMAIL PROTECTED] wrote: Hi take 1000 [1..3] still yields [1,2,3] I thought it was supposed to return an error. [..] If for some reason you want a version that does return an error in that situation, you could

Re: [Haskell-cafe] Is take behaving correctly?

2007-09-12 Thread Henning Thielemann
On Wed, 12 Sep 2007, Conor McBride wrote: Hi folks On 12 Sep 2007, at 00:38, Brent Yorgey wrote: On 9/11/07, PR Stanley [EMAIL PROTECTED] wrote: Hi take 1000 [1..3] still yields [1,2,3] I thought it was supposed to return an error. [..] If for some reason you want a version that does

Re: [Haskell-cafe] Is take behaving correctly?

2007-09-12 Thread Dan Weston
One idiom I rely on pretty often is (id tail) uncurry (zipWith f) to do pairwise binary operations (though I suspect an Applicative functor might be a better way to go?). E.g. my solution for ProjectEuler problem #18 (max sum of vertical path through a triangle of integers) is: f =

Re: [Haskell-cafe] Is take behaving correctly?

2007-09-12 Thread ok
On 12 Sep 2007, at 8:08 pm, [EMAIL PROTECTED] wrote: take 1000 [1..3] still yields [1,2,3] You can think about take n as: Take as much as possible, but at most n elements. This behavior has some nice properties as turned out by others, but there are some pitfalls. One of the very nice

Re: [Haskell-cafe] Is take behaving correctly?

2007-09-11 Thread Tim Chevalier
On 9/11/07, PR Stanley [EMAIL PROTECTED] wrote: Hi take 1000 [1..3] still yields [1,2,3] I thought it was supposed to return an error. Any ideas? No, that's the behavior for take specified in the Haskell 98 report: http://haskell.org/onlinereport/standard-prelude.html -- take n, applied to a

Re: [Haskell-cafe] Is take behaving correctly?

2007-09-11 Thread Brent Yorgey
On 9/11/07, PR Stanley [EMAIL PROTECTED] wrote: Hi take 1000 [1..3] still yields [1,2,3] I thought it was supposed to return an error. Any ideas? Thanks, Paul If for some reason you want a version that does return an error in that situation, you could do something like the following:

Re: [Haskell-cafe] Is take behaving correctly?

2007-09-11 Thread PR Stanley
I suppose I'm thinking of head or tail - e.g. head [] or tail []. I'm trying to write my own version of the find function. I have a few ideas but not quite sure which would be more suitable in the context of FP. Any advice would be gratefully received - e.g. do I use recursion, list

Re: [Haskell-cafe] Is take behaving correctly?

2007-09-11 Thread Don Stewart
byorgey: On 9/11/07, PR Stanley [EMAIL PROTECTED] wrote: Hi take 1000 [1..3] still yields [1,2,3] I thought it was supposed to return an error. Any ideas? Thanks, Paul If for some reason you want a version that does return an error in that situation,

Re: [Haskell-cafe] Is take behaving correctly?

2007-09-11 Thread Brent Yorgey
On 9/11/07, Don Stewart [EMAIL PROTECTED] wrote: byorgey: On 9/11/07, PR Stanley [EMAIL PROTECTED] wrote: Hi take 1000 [1..3] still yields [1,2,3] I thought it was supposed to return an error. Any ideas? Thanks, Paul If for some reason you want a

Re: [Haskell-cafe] Is take behaving correctly?

2007-09-11 Thread John Meacham
On Tue, Sep 11, 2007 at 07:38:18PM -0400, Brent Yorgey wrote: On 9/11/07, PR Stanley [EMAIL PROTECTED] wrote: Hi take 1000 [1..3] still yields [1,2,3] I thought it was supposed to return an error. Any ideas? Thanks, Paul If for some reason you want a version that does return an

Re: [Haskell-cafe] Is take behaving correctly?

2007-09-11 Thread PR Stanley
Let me get this right, are you saying it's unsafe when it returns an error? Paul At 00:40 12/09/2007, you wrote: byorgey: On 9/11/07, PR Stanley [EMAIL PROTECTED] wrote: Hi take 1000 [1..3] still yields [1,2,3] I thought it was supposed to return an error. Any

Re: [Haskell-cafe] Is take behaving correctly?

2007-09-11 Thread Don Stewart
prstanley: I suppose I'm thinking of head or tail - e.g. head [] or tail []. I'm trying to write my own version of the find function. I have a few ideas but not quite sure which would be more suitable in the context of FP. Any advice would be gratefully received - e.g. do I use

Re: [Haskell-cafe] Is take behaving correctly?

2007-09-11 Thread Don Stewart
byorgey: On 9/11/07, Don Stewart [EMAIL PROTECTED] wrote: byorgey: On 9/11/07, PR Stanley [EMAIL PROTECTED] wrote: Hi take 1000 [1..3] still yields [1,2,3] I thought it was supposed to return an error. Any ideas?

Re: [Haskell-cafe] Is take behaving correctly?

2007-09-11 Thread Don Stewart
prstanley: Let me get this right, are you saying it's unsafe when it returns an error? Partial functions may crash your program, so that's unsafe by some definitions, yep. We have tools that analyse programs for such bugs, in fact (Neil's `catch' program). -- Don

Re: [Haskell-cafe] Is take behaving correctly?

2007-09-11 Thread Derek Elkins
On Tue, 2007-09-11 at 16:48 -0700, Don Stewart wrote: byorgey: On 9/11/07, Don Stewart [EMAIL PROTECTED] wrote: byorgey: On 9/11/07, PR Stanley [EMAIL PROTECTED] wrote: Hi take 1000 [1..3] still yields [1,2,3] I thought it