I want to define types that happen to be backed by the same type (say, FirstName
and LastName
, which are both string
s), but I want them to be type-checked so that I cannot mix-and-match them by mistake:
> type FirstName = string;;
type FirstName = string
> type LastName = string;;
type LastName = string
> let n : FirstName = "John";;
val n : FirstName = "John"
//I wish this were caught:
> let l : LastName = n;;
val l : LastName = "John"
Is there a way to do this in F#, short of defining a record type or somesuch?