inits
Tim Toorop
timtoorop at quicknet.nl
Sat Apr 8 15:36:04 EDT 2006
Aaron Denney wrote:
> On 2006-04-08, Chris Kuklewicz <haskell at list.mightyreason.com> wrote:
>
>>> Is the head of the inits of undefined really an error?
>>> Since the head of inits [] is also [] ...
>>> But if you really want that undefined to produce an error.. you could
>>> just :
>>> inits' xn@(_:_) = zipWith take [0..] $ map (const xn) $ undefined:xn
>>> inits' _ = undefined
>>>
>>>
>>>
>> Exactly. Now inits' *is* a drop in replacement for inits.
>>
>
> Right, but the new spiffy inits seems to be a strict superset. Does
> anything plausibly depend on the strictness of the original. I think it
> was written that way for clarity, not for the strictness properties.
>
>
The inits' _ = undefined can be left out, but may be useful to some
clarity.
On the other hand, I think the new spiffy inits is quite clear once you
notice why its map (const xn) $ undefined:xn
This version doesn't use a weird recursive function.
Its just.. the definition of inits I think.
first element of inits, take the first element.
2nd element of inits, take the first plus the next element
...
But that's just my logic... probably why I wrote it like this in the
first place
( just wanted to see if I could write the inits without using a book ;) )
More information about the Libraries
mailing list