Q:

SML: difference between type and datatype

I'm pretty new at SML and I would like to make sure I really know the basics. What is the difference between type and datatype in SML, and when to use which?

A:

type declarations just give another name to an existing type. Declaring type t = int * int simply means that you can now write t instead of int * int - it doesn't actually provide any functionality.
datatype definitions let you create brand new types by introducing new data constructors. Data constructors are the keywords and symbols you use to create and pattern-match values, such as the list type's nil and ::. There's nothing particularly special about those identifiers; you can define them yourself as easily as this:
datatype 'a list = nil | :: of 'a * 'a list

A:

Datatypes in sml can have more than one type, e.g.
datatype a = SomeType | SomeOtherType

You can use them when type-checking, e.g.
fun doThings (var : a) : bool =
    case var of
       (SomeType) => true
       (SomeOtherType) => false

