|
|
Warp wrote:
> Invisible <voi### [at] devnull> wrote:
>> Mine works for *any* type that supports the + operator too. ;-)
>
> Does it work for things like balanced binary trees, double-ended queues,
> arrays and strings (ie. sum the ascii values of the characters in a string)?
> In other words, does it work for all possible containers which items you
> can iterate over?
The implementation I posted works only for lists. (And this - or
something equivilent to it - is what the standard library actually
contains.)
> No, I'm not saying that with the proper language it wouldn't be possible
> to make such a function as a short one-liner. I'm just curious to know if
> Haskell is such a language.
It would be perfectly possible to define a class that allows the
iteration of arbitrary collections. But such a thing is not currently
present in the standard libraries.
As I say, it seems the currently "accepted way" is to define a
transformation from any iteratable structure into a list, and then apply
list-specific operations there. The compiler seems to be rather good at
removing the apparent overhead with this method.
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|