plum-umd / abstracting-definitional-interpreters

Abstracting Definitional Interpreters
67 stars 2 forks source link

tell singleton #10

Closed dvanhorn closed 8 years ago

dvanhorn commented 8 years ago

The ev-trace and ev-reach functions only differ in that they use tell-trace and tell-reach giving either singleton sets or lists respectively. Is there some way to unify this and get use a ev-tell function that just uses the underlying tell operation? In order to this, tell needs to take an element rather than a collection.

Just a thought as I write about this stuff. Trace and reach have a lot in common but their difference just comes down to 1) names and 2) constructing different singletons.

davdar commented 8 years ago

Yeah you could do this in an analogous way to the way we treat the store. Give an abstract interface to tell, call it output, where output takes a single element, and the implementation of output decides whether or not the element should be smashed into a set or concatenated to a list. Then both ev-reach and ev-trace can be the same evaluator parameterized over this output interface.

davdar commented 8 years ago

In fact, I think it makes a nice story this way; since the store is an abstract interface, and it can choose how it stores things (single-vs-set), also make the output an abstract interface, and it can choose how it outputs things (list-vs-set).

dvanhorn commented 8 years ago

I guess what I want is for output to use the List0 or Pow0 to know how to add things.

davdar commented 8 years ago

Ah right, the monad needs ListO or PowO to know how to combine things... I guess if you go this route, you're looking at two different monad stacks, one for ev-reach and one for ev-trace, and two different implementations of output, one which knows the output is a list and concats to the end, and one which knows the output is a set and adds it to the set. Hm.

davdar commented 8 years ago

whereas currently, you only need one monad stack for both evaluators I think.

davdar commented 8 years ago

oh shit no, you need two different monads. ListO vs PowO, event for the current setup.

dvanhorn commented 8 years ago

That's right: currently there are two stacks. I think what would be better is two stacks, but one ev-tell "mixin". But I'm currently just sweeping this under the rug.

labichn commented 8 years ago

Potential solution in #11. This is the best we can do with the current signatures. DD, is there a name for monoids with a singleton injection (e.g. (λ (x) (set x)), (λ (x) (list x)))? We could unify the evs if we gave that a name (or just hid it behind your proposed output).