Re: [stack] Meta-combinators?
"Christopher Diggins" <[email protected]>
| Newsgroups | gmane.comp.lang.concatenative |
|---|---|
| Message-ID | <[email protected]> |
On 1/24/07, William Tanksley, Jr <[email protected]> wrote: > > Christopher Diggins <[email protected]> wrote: > > I have been intrigued by two typed-combinators which I haven't noticed > > in Joy, and that I am considering adding to Cat. > > I am calling them producer and consumer. > > > consumer : (('A -> 'B) -> ('A -> )) > > producer : ('A ('A -> 'B) -> 'A ( -> 'B)) > > > The consumer transforms any function into a new function which > > produces nothing, but consumes what was expected. > > A more general form might be a word that "consumes" only the first > argument of a multiargument function, ala: > > consumer : ('A -> B 'C) -> ('A -> 'C)) > > (I hope I got your notation right. I'm also not particular on which > side of the function the arguments get consumed.) The notation is correct except I use little letters for single arguments and big letters for multiple-arguments. The tick indicates that it is a type variable. > The obvious implementation, in terms of Joy quotations, would be to > concatenate the original function with a stack shuffle that destroys > the appropriate output. So the solution is simple in Cat (and Joy as well) to this case: In Cat "[quote] dip compose" And in Joy: "[unit] dip cat" What I am looking for though is something which curries all of the consumed arguments, or pops all the produced results. The more general problem is how to construct a combinator which can curry all arguments for any given function. Stated differently the challenge is to write a function which can compute the number of arguments or number of results of any given function. > > The producer transforms any function into a new function which > > consumes nothing, but produces the result as if it was fed the stack > > configuration when it was created. > > > Production is like a generalized form of currying. > > So you'd prepend the input data value onto (a copy of) the input function. Yes. > > How would this be possible in the general case in Joy? Or Factor, or > > any other concatenative language for that matter? > > Currying is equivalent to concatenation. Yes. > > Christopher Thanks for your comments. P.S. Let me know when you have a chance to review the Cat paper (http://www.cat-language.com/paper.html). I am considering submitting it (with revisisons) to the upcopming Trends in Functional Programming symposium (deadline is February 1st.) Thanks -- http://www.cdiggins.com