|
|
Warp wrote:
> Which got me thinking: Does foldl1 in haskell work for data containers
> other than lists?
No. The function specified in the language standard works only for lists.
However, there *is* an alternate version in one of the libraries that
does work for any suitable container. (Confusingly, it has the same
name, even though it's a different function.) Almost all container
libraries supply their own home-grown fold function, which may or may
not have the same name and/or type signature.
This is something of a known problem. A container like lists can hold
*any* type of data, but the Set container can only hold "ordered" data.
We have yet to reach a concensus about how to encode this into the type
system. (Dependent types look like the future, but that's an
experimental new feature that isn't part of any official standard, etc.)
> What if you want to apply it to only a sub-range inside
> the data container rather than to the entire container? (Can you do it
> without copying the sub-range to a separate container?)
Notionally, no.
Physically? Ask the optimiser.
(Remember, your "container" might not actually *exist* in its entirity
until you try to "do" something with it...)
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|