Abstracting over mutability for cast types