Created
February 17, 2013 20:00
-
-
Save GregRos/4973114 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* 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