Re: [Haskell-cafe] Need some help with an infinite list

2009-06-17 Thread Matthew Brecknell
Reid Barton wrote: I'm surprised everyone is giving clever recursive solutions rather than concatMap (\n - replicateM n ['a'..'z']) [1..] Regards, Reid Well, you've lost efficient sharing with respect to my previous solution and one other. But it's a fair call, so... tail $ concat $

Re: [Haskell-cafe] Need some help with an infinite list

2009-06-17 Thread Henning Thielemann
On Wed, 17 Jun 2009, Richard O'Keefe wrote: On 17 Jun 2009, at 2:01 pm, Richard O'Keefe wrote: On second thoughts, let strings = : [pref++[last] | pref - strings, last - ['a'..'z']] in tail strings last:pref instead of pref++[last] should do more sharing. You can also write it this way:

Re: [Haskell-cafe] Need some help with an infinite list

2009-06-17 Thread Henning Thielemann
On Wed, 17 Jun 2009, Matthew Brecknell wrote: Reid Barton wrote: I'm surprised everyone is giving clever recursive solutions rather than concatMap (\n - replicateM n ['a'..'z']) [1..] Regards, Reid Well, you've lost efficient sharing with respect to my previous solution and one other.

[Haskell-cafe] Need some help with an infinite list

2009-06-16 Thread GüŸnther Schmidt
Hi guys, I'd like to generate an infinite list, like [a, b, c .. z, aa, ab, ac .. az, ba, bb, bc .. bz, ca ...] When I had set out to do this I thought, oh yeah no prob, in a heartbeat. Uhm. Help, pls! Günther PS: I know this should be a no-brainer, sry

Re: [Haskell-cafe] Need some help with an infinite list

2009-06-16 Thread Daniel Peebles
One (rather ugly) option is: tail . map (\y - showIntAtBase 26 (\x - chr (x + 96)) y ) $ [0..] but I'm sure there's a prettier one out there :) On Tue, Jun 16, 2009 at 8:28 PM, GüŸnther Schmidtgue.schm...@web.de wrote: Hi guys, I'd like to generate an infinite list, like [a, b, c .. z, aa,

Re: [Haskell-cafe] Need some help with an infinite list

2009-06-16 Thread Ross Mellgren
Here's a way using list comprehensions: Prelude Data.List take 1000 $ concat.concat $ [ [ replicate n c | c - ['a'..'z'] ] | n - [1..] ] abcdefghijklmnopqrstuvwxyzaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvw

Re: [Haskell-cafe] Need some help with an infinite list

2009-06-16 Thread Thomas Davie
letterCombos = map (:[]) ['a'..'z'] ++ concatMap (\c - map ((c++) . (: [])) ['a'..'z']) letterCombos Not hugely efficient, if you generate the strings in reverse then you can use (c:) rather than ((c++) . (:[])), but that may not be useful to you. Bob On 17 Jun 2009, at 02:28, GüŸnther

Re: [Haskell-cafe] Need some help with an infinite list

2009-06-16 Thread José Prous
this appears to work: alphabet=map (\x-x:[]) ['a'..'z'] series=alphabet++[x++y|x-series,y-alphabet] On Tue, Jun 16, 2009 at 8:28 PM, GüŸnther Schmidt gue.schm...@web.dewrote: Hi guys, I'd like to generate an infinite list, like [a, b, c .. z, aa, ab, ac .. az, ba, bb, bc .. bz, ca ...]

Re: [Haskell-cafe] Need some help with an infinite list

2009-06-16 Thread Richard O'Keefe
On 17 Jun 2009, at 12:28 pm, GüŸnther Schmidt wrote: Hi guys, I'd like to generate an infinite list, like [a, b, c .. z, aa, ab, ac .. az, ba, bb, bc .. bz, ca ...] When I had set out to do this I thought, oh yeah no prob, in a heartbeat. Let me change this slightly.

Re: [Haskell-cafe] Need some help with an infinite list

2009-06-16 Thread Daniel Peebles
My solution attempted to exploit this using Numeric.showIntAtBase but failed because of the lack of 0 prefixes in the numbers. If you can find a simple way to fix it without duplicating the showIntAtBase code, I'd be interested! On Tue, Jun 16, 2009 at 10:01 PM, Richard O'Keefeo...@cs.otago.ac.nz

Re: [Haskell-cafe] Need some help with an infinite list

2009-06-16 Thread Matthew Brecknell
Thomas Davie wrote: letterCombos = map (:[]) ['a'..'z'] ++ concatMap (\c - map ((c++) . (: [])) ['a'..'z']) letterCombos Not hugely efficient, if you generate the strings in reverse then you can use (c:) rather than ((c++) . (:[])), but that may not be useful to you. Bob I think

Re: [Haskell-cafe] Need some help with an infinite list

2009-06-16 Thread Richard O'Keefe
On 17 Jun 2009, at 2:01 pm, Richard O'Keefe wrote: On second thoughts, let strings = : [pref++[last] | pref - strings, last - ['a'..'z']] in tail strings seems more Haskellish than the stupidly clever counting-based code I had in mind. With this it's much easier to see what it's up

Re: [Haskell-cafe] Need some help with an infinite list

2009-06-16 Thread Dean Herington
At 4:25 PM +1200 6/17/09, Richard O'Keefe wrote: On 17 Jun 2009, at 2:01 pm, Richard O'Keefe wrote: On second thoughts, let strings = : [pref++[last] | pref - strings, last - ['a'..'z']] in tail strings seems more Haskellish than the stupidly clever counting-based code I had in mind.

Re: [Haskell-cafe] Need some help with an infinite list

2009-06-16 Thread Reid Barton
On Wed, Jun 17, 2009 at 02:28:55AM +0200, Gü?nther Schmidt wrote: Hi guys, I'd like to generate an infinite list, like [a, b, c .. z, aa, ab, ac .. az, ba, bb, bc .. bz, ca ...] I'm surprised everyone is giving clever recursive solutions rather than concatMap (\n - replicateM n

Re: [Haskell-cafe] Need some help with an infinite list

2009-06-16 Thread Casey Hawthorne
On Wed, 17 Jun 2009 00:45:56 -0400, you wrote: And here's a version along similar lines that avoids (++) for greater sharing and efficiency: let sss = [] : [ [ c:s | c - ['a'..'z'], s - ss ] | ss - sss ] in concat (tail sss) Sheer genius! I just inverted it since I like to see the main