Skip to content

Instantly share code, notes, and snippets.

@GregRos
Created February 17, 2013 20:00
Show Gist options
  • Save GregRos/4973114 to your computer and use it in GitHub Desktop.
Save GregRos/4973114 to your computer and use it in GitHub Desktop.
(* Fun fact: It is possible to define the Cons (::) symbolic union case
used by FSharp's own list data structures for your own discriminated unions. *)
type MyList<'t> =
| Nil
| (::) of 't * MyList<'t>
let x = 100::99::98::Nil
//The compiler will infer this to be of type MyList<int> since I explicitly used the Nil union case of MyList
//And not the [] union case of List.
//You can do this as well, but it doesn't really work as expected.
type MyList2<'t> =
| ([])
| (::) of 't * MyList<'t>
let x = 5::4::3::[]
//The compiler will always infer the basic List type over my own discriminated union.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment