Thu May 16 09:16:20 EDT 2019

Local context

So I need some iteration pattern that can associate a primitive term
to some context.  To use Traversable, there needs to be a Functor
structure.  What is the contained type in this case?

I'd say the basic element would be the primitive expression.  We want
to modify the indexing there.

First, make it such that Form can take a single binding parameter.

EDIT: Done. It was easy, and instances can be derived
automatically. This is awesome.

So it should be easy now to create a primitive transformation
operation based on context.  Basically, traverse, with a custom monad.

Looks like there is two different ways to look at this:

- Custom, using a monadic iteration based on the generalized fold

- Flattened, using standard iteration patterns.

It appears that there needs to be some routine that moves information
between the structure that is hidden to the functor (loop indices),
into the contained values.

EDIT: Ive created the function below, exposes the path to the functor

annotate :: Program b -> Program ([Index], b)
annotate (Program fs) = Program $ forms [] fs where
  forms path fs = map (form path) fs
  form path (LetPrim b) = LetPrim (path, b)
  form path (LetLoop i fs) = LetLoop i $ forms (i:path) fs

Now that could be tucked away in a Monad.  Is it necessary though?  I
kind of like this explicit structure.