Meta-combinators?
Christopher Diggins — 2007-01-24 22:30:01
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.
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.
How would this be possible in the general case in Joy? Or Factor, or
any other concatenative language for that matter?
Thanks,
Christopher
--
http://www.cdiggins.com
William Tanksley, Jr — 2007-01-24 23:27:11
Christopher Diggins <
cdiggins@...> 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 obvious implementation, in terms of Joy quotations, would be to
concatenate the original function with a stack shuffle that destroys
the appropriate output.
> 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.
> 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.
> Christopher
-Billy
Christopher Diggins — 2007-01-25 01:19:18
On 1/24/07, William Tanksley, Jr <
wtanksleyjr@...> wrote:
>
> Christopher Diggins <cdiggins@...> 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
Chris Double — 2007-01-25 01:38:37
On 1/25/07, Christopher Diggins <
cdiggins@...> wrote:
> 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.
In Factor you can find the stack effect of most words using 'infer'.
'infer' can compute a quotations stack effect based on the effects of
the words in quotation. From this you can write a word that curries
the correct number of arguments to the word.
The LAZY: word in the lazy lists library for example uses the stack
effect of the word to curry the arguments onto the words quotation to
do lazy evaluation.
Another option in Factor is to use 'datastack' and 'set-datastack'.
These words let you get access to the stack directly and could be used
to save/restore as needed.
Chris.
--
http://www.bluishcoder.co.nz
John Cowan — 2007-01-25 03:46:29
Christopher Diggins scripsit:
> 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.
I think that can be done in Joy provided that the program doesn't
use any of the small number of Joy words with variable stack effects.
--
A mosquito cried out in his pain, John Cowan
"A chemist has poisoned my brain!"
http://www.ccil.org/~cowan
The cause of his sorrow
cowan@...
Was para-dichloro-
Diphenyltrichloroethane. (aka DDT)
Christopher Diggins — 2007-01-25 04:58:16
That's an interesting usage, thanks Chris.
On 1/24/07, Chris Double <chris.double@...> wrote:
>
> On 1/25/07, Christopher Diggins <cdiggins@...<cdiggins%40gmail.com>>
> wrote:
> > 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.
>
> In Factor you can find the stack effect of most words using 'infer'.
> 'infer' can compute a quotations stack effect based on the effects of
> the words in quotation. From this you can write a word that curries
> the correct number of arguments to the word.
>
> The LAZY: word in the lazy lists library for example uses the stack
> effect of the word to curry the arguments onto the words quotation to
> do lazy evaluation.
>
> Another option in Factor is to use 'datastack' and 'set-datastack'.
> These words let you get access to the stack directly and could be used
> to save/restore as needed.
>
> Chris.
> --
> http://www.bluishcoder.co.nz
>
>
--
http://www.cdiggins.com
[Non-text portions of this message have been removed]
William Tanksley, Jr — 2007-01-25 15:15:23
John Cowan <
cowan@...> wrote:
> > 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.
> I think that can be done in Joy provided that the program doesn't
> use any of the small number of Joy words with variable stack effects.
And is very careful with loops, conditionals, and recursion, OR is
written in a way that allows the parser to determine when it halts and
that it always halts. The latter condition makes me shudder.
> A mosquito cried out in his pain, John Cowan
-Billy
William Tanksley, Jr — 2007-01-25 15:12:08
Christopher Diggins <
cdiggins@...> wrote:
> > 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.
All at once? From a naked stack? I don't like that. It's a variable
stack effect. If you pulled them out of a list I'd be happier.
Variable stack effects make me uncomfortable.
> 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 same function can compute whether and when the given function
halts -- consider a function that consists of a loop, each iteration
of which places an integer on the stack. Knowing how many integers it
produces is equivalent to knowing how many iterations it performs.
(If we limit ourself to nonvariable stack effects the problem is
simple -- but it's EASY to build a function with variable effects;
recursion and conditionals are sufficient, unless you have a type
system with special rules.)
> > > 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.
It's not possible in Joy, because Joy doesn't have a type system.
> 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.)
Ouch! I can't do it. Sorry. I've got two huge work deadlines and am
recovering from the stomach flu. I'll print it out to read on the
train home today, but no promises... I'm working on 1 hour of sleep,
and you might not be able to use what I produce :-).
> http://www.cdiggins.com
-Billy