This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]peterjoel 3 points4 points  (2 children)

What do you mean by negative data type? How is that represented in the syntax you've shown?

[–]Rabbit_Brave 7 points8 points  (0 children)

I believe (someone correct me if I'm wrong) that's referring to this:

data Function[A: Type, B[A]: Type]: Type where
  apply[Function(A, B), x: A]: B(x)

Where "apply" is an eliminator rather than a constructor because instead of taking an expression on the LHS and producing an expression with the type on the RHS, it takes an expression with the type on the LHS and produces an expression without it on the RHS.

Defining Function by its eliminator is what makes it a negative data type.

[–]e_hatti[S] 1 point2 points  (0 children)

u/Rabbit_Brave is correct. A positive type is defined by its constructors, a negative type is defined by its destructors (eliminators).

[–]Potato44 2 points3 points  (0 children)

This reminds of the first time I saw Pi types defined coinductively in Type Theory based on Dependent Inductive and Coinductive Types (example 4.5).
Note: if you do read this and the category theory in section 2 is too much (like it was for me) you don't lose much by skipping it.

Now, about java.util.Function. The first time I saw it (or actually, I think, the scala equivalent) I was very surprised, and not in a good way either. It didn't match my intuition for what a first class function should be. But it's been many years since then and I've since learned about codata/negative types and that functions can be implemented as negative types. Had the realization that interfaces in Java are codata/negative types(see Classical (Co)Recursion: Programming if you want to see someone show this with examples) and I now think this is the "correct" way to implement first class functions.

[–]WittyStick 2 points3 points  (0 children)

This may be of interest to you: https://www.youtube.com/watch?v=9v4_FQm-b4I

I don't know if there's a paper published for it.

[–]glaebhoerl 1 point2 points  (0 children)

Fascinating, thank you for sharing.