I agree with Petr take, but for completeness, note that you can only use phantom types when you have a generic type, to use them so that you cannot do anything with simple string inputs. Instead, you can do something like this:
type safeString<'a> = { value : string } type Path = class end type FileName = class end let combinePath (path:safeString<Path>) (filename:safeString<FileName>) = ... let myPath : safeString<Path> = { value = "C:\\SomeDir\\" } let myFile : safeString<FileName> = { value = "MyDocument.txt" } // works let combined = combinePath myPath myFile // compile-time failure let combined' = combinePath myFile myPath
source share