Created
February 16, 2017 13:54
-
-
Save alfonsogarciacaro/27335d9fbd43b8d1526a086bf0311964 to your computer and use it in GitHub Desktop.
Implicit conversion for erased unions
This file contains hidden or 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
type U2<'a,'b> = | |
| Case1 of 'a | |
| Case2 of 'b | |
static member op_Implicit(x:'a) = U2.Case1 x | |
static member op_Implicit(x:'b) = U2.Case2 x | |
let inline (!|) (x:^a) : ^b = ((^a or ^b) : (static member op_Implicit : ^a -> ^b) x) | |
let foo (arg: U2<string, int>) = () | |
foo(!|"hello") | |
foo(!|5) | |
//foo(!|5.) // Doesn't compile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment