Meta-Combinators?
I have been intrigued by two typed-combinators which I haven’t noticed elsewhere that I am considering adding to the Cat primitives. 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.
I wonder whether this would be possible in the general case in Joy? Or Factor, or any other concatenative language for that matter?
One utility is the ability to define a generic dup function. Consider:
define dup_production : ('A ('A -> 'B) -> 'B 'B)
{ producer dup dip eval }
Using this I can write something like:
define abcdabcd { [abcd] dup_production }