monte-language / spotter

Experimental low-level Monte runtime in OCaml
Do What The F*ck You Want To Public License
4 stars 1 forks source link

objects are natural transformations in a category of messages and effects: impact? #16

Open dckc opened 3 years ago

dckc commented 3 years ago

@MostAwesomeDude says:

It explains why it's so hard to actually write recursive objects.

context:

Settling Foundations Feb 10 to Friam

@cwebber

I feel like I also finally got a certain amount of way for category theory

@MostAwesomeDude

... I often think of set theory as 0-category theory. Like, it's categories but without arrows. ... Maybe now the slogan "objects are natural transformations in a category of messages and effects" can get some breathing room: https://hackage.haskell.org/package/objective hasknewtype Object f g = Object { runObject :: forall x. f x -> g (x, Object f g) } where f and g are Functor-ish. Transform messages into effects, optionally becoming a new object.

I said package/objective looks cool... does it shed any light on https://github.com/monte-language/spotter ?

@MostAwesomeDude

Yeah. It explains why it's so hard to actually write recursive objects.

MostAwesomeDude commented 3 years ago

Spotter is obviously not in a state of being maintained or growing. Indeed, it never got off the ground beyond a certain point. Part of that is a failure to define what we wanted to achieve; feature parity with Typhon was not ever really on the table, and so we should have had specific other goals that we wanted to meet.

But the other part of it is a mismatch between what OCaml provides in terms of object rights and what Monte requires. We have to erase auditors in order to get to OCaml-level objects, and then we're constrained by the type system. I don't know what I expected.

objective could give us a way around some of this, by sending objects to NTs in a category which has the effects that we want. The 0-data are internal OCaml/Haskell values, the 1-data are Applicative Functors (probably Monads) which store the effects, and the 2-data is a transformation on the effects which is agnostic to the actual values being plumbed around.

So why do I say that it's "so hard to actually write recursive objects"? By analogy with ejectors, it's hard to eject in a way that allows for restarting a computation from the ejection site; similarly, it's hard to mutate an object and also return a return value. objective makes this as easy as possible in the same way that the logic monad from lib/logji allows for ejectors to jump back to a half-finished computation: By returning a pair def [result, nextComputation] := compute(computation) which designates the next destination and then implementing a trampoline.