Skip to content

Instantly share code, notes, and snippets.

@Savelenko
Savelenko / PhantomDemo.fs
Last active September 8, 2020 23:56
Phantom types with private representation
namespace PhantomTypes
module User =
type Username<'a> = private Username of string with
member u.Value = let (Username username) = u in username
type Short = interface end
type Full = interface end
@Savelenko
Savelenko / GADTMotivation.fs
Last active June 20, 2025 21:38
Motivated simulation of GADTs in F#, quite motivational
module GADTMotivation
(*
Here is a simple motivational example for GADTs and their usefulness for library design and domain modeling. Suppose we
need to work with settings which can be displayed and adjusted in a GUI. The set of possible setting "types" is fixed
and known in advance: integers, strings and booleans (check-boxes).
The GUI should show an example value for each possible setting type, e.g. 1337 for an integer setting and "Hello" for a
string setting. How can we model this small domain of setting types and computing example values?
*)