A bunch of useful SML functions