Skip to content

Instantly share code, notes, and snippets.

@palladin
Last active September 25, 2021 17:52
Show Gist options
  • Save palladin/e3a2d44688c7a451cc0f to your computer and use it in GitHub Desktop.
Save palladin/e3a2d44688c7a451cc0f to your computer and use it in GitHub Desktop.
Overload resolution and inline trick
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)
@kurtschelfthout
Copy link

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.

@kurtschelfthout
Copy link

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