POV-Ray : Newsgroups : povray.off-topic : A comparison : Re: A comparison Server Time
10 Oct 2024 23:19:36 EDT (-0400)
  Re: A comparison  
From: Invisible
Date: 20 Mar 2008 08:06:33
Message: <47e26159$1@news.povray.org>
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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.