Last active
September 25, 2021 17:52
-
-
Save palladin/e3a2d44688c7a451cc0f to your computer and use it in GitHub Desktop.
Overload resolution and inline trick
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 Term<'a>() = class end | |
type Tuples = Tuples with | |
static member inline (?<-) (_ : Tuples, _ : Term<_>, _ : Term<_>) = 0 | |
static member inline (?<-) (_ : Tuples, (_:Term<_>,_:Term<_>),(_:Term<_>, _:Term<_>)) = 2 | |
static member inline (?<-) (_ : Tuples, a:bool, b:bool) = 3 | |
let inline call_2 (t:^t,a:^a,b:^a) : int = | |
(t ? (a) <- b ) | |
let t = call_2 (Tuples,Term<int>(),Term<int>()) | |
let t2 = call_2 (Tuples,(Term<int>(),Term<int>()),(Term<int>(),Term<int>())) | |
let t3 = call_2 (Tuples, true, false) | |
let inline call a b : int = | |
call_2 (Tuples, a, b) |
Incidentally, if you remove the bool overload, again the call
is properly generalized.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for chipping in!
Ah yes, the only ternary operator :)
Though it has a problem with
let inline call a b = call_2 (Tuples, a, b)
- this ends up being restricted to bool -> bool -> int.FsControl seems to get away with this without using operators. I think there's something we're missing.