[Haskell-beginners] Re: Defeating type inference

Will Ness will_n48 at yahoo.com
Sat Feb 28 01:50:59 EST 2009

Philip Scott <pscott <at> foo.me.uk> writes:

> So I puzzled for a little bit about how to do this in the most Haskelly 
> way and I thought of this
> months = concat (range (Jan, Dec) : months)
> Which should work, right**
> ** though I am pretty sure this is the Wrong Way to do this. I suspect 
> concat takes O(n) time - more elegant approaches would be welcomed!

Nobody seem to relate to that point. No, it's not O(n) time. It's O(1) time. 
It's just one lazy definition. The _access_ is O(n) and the definition kicks in 
at the right time while riding along with the access - take, drop or whatever - 
along the list. It is always just taking one head element at a time off the 
first list, if not empty, or else switching to the next one - and feeding that 
element to list access. If it's not eliminated completely by compilation. :)

More information about the Beginners mailing list