[mercury-users] Idea for a currying library

Peter Ross petdr at cs.mu.OZ.AU
Tue Jan 11 08:42:40 AEDT 2000


On 07-Jan-2000, Ralph Becket <rbeck at microsoft.com> wrote:
> A while back there was a discussion about how
> best to deal with the issue of currying, in
> particular how one might deal with the fact
> that often one has to permute arguments in
> higher order to code to make things work.
> Richard O'Keefe, I think, made the suggestion
> that some extra syntax be introduced, e.g.
> 
> 	P = foo(X, #2, Y, #1)
> 
> would translate into
> 
> 	P = (func(A, B) = foo(X, B, Y, A))
> 
> or somesuch.  I, for one, would find such a
> facility very useful.
> 
> If adding more syntax is undesirable/too much
> trouble for now, it occurs to me that we could
> get some way towards solving the problem with
> a suitable library.  The idea would be to
> provide currying functions for all the non-
> standard argument permutations for all functions
> up to a given arity, say 5.  This library would
> look something like the following:
> 
> 	% cy12 omitted as unnecessary.
> 	:- func cy21(func(T1, T2) = T3, T2, T1) = T3.
> 	cy21(F, A, B) = F(B, A).
> 
> 	% cy123 omitted as unnecessary.
> 
> 	:- func cy132(func(T1, T2, T3) = T4, T1, T3, T2) = T4.
> 	cy132(F, A, B, C) = F(A, C, B).
> 
> 	:- func cy213(func(T1, T2, T3) = T4, T2, T1, T3) = T4.
> 	cy132(F, A, B, C) = F(B, A, C).
> 
> and so on for cy231, cy312, cy321 and on up to 
> arity 5 or whatever.
> 
> Of course, we'd almost certainly have to limit
> the library to (in, in, ..., in) = out modes to
> avoid an explosion in the size of the library.
> 
> Mind you, generalising to the case where only a
> single output is allowed might not be too bad.
> 
> Any comments?
> 
Sounds like a great idea.

Pete
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list