Change the type of grammars so that its rules are a finite map.

This uses the type system to guarantee the finite-ness invariant that
would otherwise need to appear in side-conditions.