Vrrm Development


EDSL for Debugging in haskell and diffs

Filed under: Uncategorized — whpearson @ 1:52 pm

So I’m going to do an embedded domain specific language in haskell. Mainly so I don’t have to go through all the bother of building all the interpreter plumbing.

So what will it look like roughly? As I am interested in figuring out what is going on in the virtual machine, I’ll need lots of information about how it changes. This lead me to think that a very useful idea would be the patch. So you could run the VM for number of steps and get back a list of the changes. Merge them into one and save it to disk so you can quickly get back to this state, or save every step. You could have it return a tuple of the operations and arguments ran and the diffs, and because of laziness you could select the one you want. So you could do stats on the ops ran as well.

So the main useful function would be something like…

runVrrm :: Vrrm -> n -> (Vrrm, [Instuction], [VrrmDiffList])

This would apply a diff to the vrrm state and get the new state. Hopefully you should also be able to do it backwards to turn back time.

applyDiffFor:: VrrmDiff -> Maybe Vrrm -> Maybe Vrrm
applyDiffBack:: VrrmDiff -> Maybe Vrrm -> Maybe Vrrm

It would have to be Maybe, because if you apply diff to a machine state of a different memory size or variant of the architecture would barf and return Nothing.

You could apply them with folds

foldr (applyForwardDiff) (Just startstate) diffList

Although most likely you’d want to strictly merge them into one before doing this as the temp vrrmstates would be very big.

Getting categorical

Making a VrrmDiffList a monoid seems like a good idea, basically it allows you to merge them together. As well as function that takes two diffs and composes them together you need a value that makes no difference what it is composed with. This shouldn’t be too hard.

Also I’ll note at this point that a partially applied applyDiffFor or back on a diff is an arrow, and can be used as such. Something theoretically interesting, but I am not quite sure how to use it at the moment.

I’m also interested in the symmetries implicit in the diffs implying some form of group-ness. That you can negate diff should imply some more stuff, but it is not quite a group because negate a `mappend` a = mempty. Although it could do, you would lose the information about values had changed.

A brief example how it might work to give you a flavour.

Let us say that the whole of the state is one array. A diff would be something like

newtype VrrmDiff = Diff { getStart :: Int , getLength::Int , getChangeList :: [(Int, Int)]}

The change list would assume the first Int was the original value and the second the changed value. Now you could compose the diffs in such a way that if the original value and changed value where the same it would be removed. This would make it a group.

Both VrrmDiff 0 0 [] and VrrmDiff 0 1 [(1,1)] would have the same affect on an array *, that being nothing.

* Note arrays are different from lists in haskell, I’ll use to indicate an array.


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Blog at WordPress.com.

%d bloggers like this: