[m-dev.] HO List args: fold and unfold

doug.auclair at logicaltypes.com doug.auclair at logicaltypes.com
Tue Mar 14 08:54:08 AEDT 2006


Dear all,

Hi!  I was doing some higher-order (HO) programming with lists recently, and
was subsequently surprised at some of the functions that take HO arguments.

My first surprise was func foldl/3.  When I attempted to do a sum of squares
by compose((+), converse((^), 2)), the compiler gave me the typing error:
(+), of course, is not an unary function.

So, I was wondering if something could be added to the standard library
that would treat n-ary functions as unary functions, multiply curried
(a la Haskell), and, on the listy end have fold also accept a curried
unary function that is equivalent to a binary function (call it something
like cfoldl for 'combinatory'foldleft).  I see the standard approach for 
Mercury is to create an n-ary lambda term, but it runs counter to the 
compositional style of functional programming that I follow (after all, 
why explicitly write a new lambda term when there's an equivalent 
application?).

-----

On the other side of fold is unfold.  Mercury supplies the series/3 function,
but when I tried to use it, I was stymied.  The main issue is that X0, etc,
may need to be transformed while being unfolded.  I see that Mercury follows
Haskell's unfoldr here, but I was thinking something more like Dylan's
unfold (http://www.opendylan.org/gdref/gdlibs.html -- sorry, no direct link
to the function description).  Not having the transformation function for the 
current element sometimes renders series/3 useless, so I was wondering if
 unfold could be added to the list module.

Thanks!

Sincerely,
Doug Auclair

--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list