Gut and rewrite type system