Theory and implementation methods underlying SML#