Live data from Hacker News

Dualities in functional programming

dicioccio.fr

11–20 of 28 posts

Re: Dualities in functional programming

#11

Besides those mentioned in the article, most everything in functional programming has a dual, usually by prefixing "co-". Cofunctor, coapplicative, comonoid, comonad, &c. All things with reversed arrows and varying degrees of usefulness.

That looks like category theory rather than functional programming.

Re: Dualities in functional programming

#12
post #11

Besides those mentioned in the article, most everything in functional programming has a dual, usually by prefixing "co-". Cofunctor, coapplicative, comonoid, comonad, &c. All things with reversed arrows and varying degrees of usefulness.

That looks like category theory rather than functional programming.

The two are pretty much the same when you get down to it

Re: Dualities in functional programming

#13

There is a similar duality between “require” and “provide” that I’ve been trying to work more with recently. The idea that we can require some behavior verified via a test and also provide that behavior via a fake might mean that the two can be unified (test is the dual of fake, so maybe you can get tests and fakes from the same code, that’s the hope anyways). Identifying a duality means that there might be some oppo…

that sounds very interesting

Re: Dualities in functional programming

#14
The reason null values are a problem is because most compilers do not track the difference between a nullable and a nonnullable type. If they would, then null values would indeed be similar to Nothing in the maybe type.

Re: Dualities in functional programming

#15
There exists a rich theory about duality in computation, a forgotten twin of lambda calculus: sequent calculus https://ps.cs.uni-tuebingen.de/publications/ostermann22intro... I recommend you check it out if you are at least a little curious about duality in programming.

I've been thinking about duality at the core of programming language design for a while now. Motivated by asynchronous computation and mainly focused on the question: How to build programming abstractions from input-output-duality? It is fascinating seeing the common abstractions just naturally evolve from there.

As a preliminary result I wrote a theory of computation: http://perma-curious.eu/e3lli/core/ It describes how to go from input-output-duality to an advanced lisp dialect.

Re: Dualities in functional programming

#16

There is a similar duality between “require” and “provide” that I’ve been trying to work more with recently. The idea that we can require some behavior verified via a test and also provide that behavior via a fake might mean that the two can be unified (test is the dual of fake, so maybe you can get tests and fakes from the same code, that’s the hope anyways). Identifying a duality means that there might be some oppo…

Things can have two dual dimensions, resulting in four concepts & four relationships.

Perhaps the fourth concept is “event” giving us:

Precondition Postcondition, the relationship between a condition before & after a computation.

Event side effect, the relationship between the environment activating a computational change, vs a computation activating an environment change.

Precondition Event, the relationship of an environmental change, triggering a computational change.

Side effect Post-condition, the relationship between a computational change, triggering an environmental change.

—-

If we think of the loop as both initiated and consumed by the environment, OR by the computation, we get dual loops through all four steps:

We have environment changes interpreted as an event by computation, which responds with an appropriate side effect, which in turn changes the environment. Environment to environment, through computation.

Or the loop can start with a side effect, causing an environmental change, whose event lets the computation react to the environments reaction to the initial side effect. Computation to computation, through envirinment.

Re: Dualities in functional programming

#17
post #12
post #11

Earlier quoted context omitted.

That looks like category theory rather than functional programming.

The two are pretty much the same when you get down to it

In my experience, what computer scientists (in particular programming language researchers) consider to be "category theory" is very different from what mathematicians (in particular those working in algebraic geometry, algebraic topology, homological/homotopical algebra, ...) consider to be the important parts of category theory.

In my very biased and unfair perspective, the "computer science perspective" on category theory is rather applying the first 50 introductory pages of a decent textbook about category theory, while for mathematicians, where category theory actually starts to become somewhat interesting is only, say, from page 150 on, when also a lot of additional mathematical concepts that actually motivate (or even necessitate) these much more complicated category theory topics have additionally become introduced.

Re: Dualities in functional programming

#18
post #12

Earlier quoted context omitted.

The two are pretty much the same when you get down to it

In my experience, what computer scientists (in particular programming language researchers) consider to be "category theory" is very different from what mathematicians (in particular those working in algebraic geometry, algebraic topology, homological/homotopical algebra, ...) consider to be the important parts of category theory. In my very biased and unfair perspective, the "computer science perspective" on categor…

But why is that a problem?

Category theory is an API for mathematics that was developed with specific applications in mind that the API seeks to unify and make easier to think about. Those application domains are algebraic geometry, algebraic topology, homological/homotopical algebra. Every API comes with trade-offs: typically an API makes one domain easier, at the cost of making other domains harder. Example: CSS is Turing complete. And I think CSS is really good at helping with styling webpages. But I would not want to write a compiler is CSS.

Computer scientists, like myself, who read from Page 150 onwards have just found the API stylised for algebraic geometry, algebraic topology, homological/homotopical algebra, ... not that useful, for applications in computer science. Unlike the first 50 pages, which have been very useful. More specifically, we found the cost of using purely categorical APIs not worth the benefits in many application domains. Maybe we are missing something, maybe we overlooked something. But, given the investments since the 1990s of computer science into category theory, I'd like to see more evidence for!

To conclude with a concrete example: why would I write a compiler using an API for homotopical algebra?

Re: Dualities in functional programming

#20
post #15

There exists a rich theory about duality in computation, a forgotten twin of lambda calculus: sequent calculus https://ps.cs.uni-tuebingen.de/publications/ostermann22intro... I recommend you check it out if you are at least a little curious about duality in programming. I've been thinking about duality at the core of programming language design for a while now. Motivated by asynchronous computation and mainly focused…

That author has a bit of a misunderstanding about Lisp:

"Lisp evaluation works by mutual recursion of eval and apply. Eval looks at an expression and if it is a function application it calls apply. Apply in turn calls eval on the arguments and invokes its function on them. This is call-by-value."

In classical Lisp and its descendants, apply is a function. Indeed, the paradigm is call by value, and therefore that function receives all of its arguments already evaluated.

When eval determines that its input form is a function call, it recurses first on eval to evaluate the argument expressions to a list of values. It then uses apply, which is a function which takes two arguments: the function to be applied, and a list object of values to be the arguments. apply doesn't do any evaluating, just the binding of the function to the arguments. eval needs this API, without which it has no way to pass a dynamically constructed argument list to a function.

It's not clear if there is a meaningful duality there; apply is a service required by eval. eval is not required by apply. apply can be written in terms of eval, but that eval cannot then use that apply. Also, it's mildly ugly, because apply has to carefully add quotes to the argument material to prevent eval from evaluating it again, so that just the desired effect is obtained of a function application and no other evaluations.

Post reply on HN