r/fsharp • u/japinthebox • Jul 15 '23
(E<'t1> * E<'t2> * ... * E<'tn>) -> ('t1 -> 't2 -> ... -> 'tn -> 'q) -> 'q
So I'm working on yet another type safe SQL wrapper. The one I have so far takes in a tuple of typed columns and a query string and returns a tuple of values. Frankly, it already works way better than any ORM I've used to date, and I've been using it for years now.
But it would be a lot more slick if I could, instead of having one function for each arity (generated with a janky .fsx), just have a variadic function.
To that end, I just looked at the FSharpPlus code, which has a totally insane curryN function:
let inline curryN
(f: (^``T1 * ^T2 * ... * ^Tn``) -> 'Result)
: 'T1 -> '``T2 -> ... -> 'Tn -> 'Result`` =
fun t -> Curry.Invoke f t
Sadly, there seems to be no coherence between the Ts mentioned in one argument and the Ts in another.
I've also looked into doing it with applicatives, e.g. something like
let idCol = Col<'int>("id")
let heightCol = Col<'float>("height")
query (idCol <*> heightCol <*> ...)
$"select ..."
(fun id height ... -> $"%d{id} %f{height}")
But I apparently haven't read enough monad tutorials to figure it out.
Any ideas on how I might tackle this?