A couple of nasty hacks later, it typechecks!

Just need to do some work on records now, then testing the decoding...