Is there a reason why I can use a generic function with different type arguments when I pass it as a local value but not when passed as parameter?
For example:
let f = id
let g (x,y) = (f x, f y)
g ( 1, '2')
works fine, but if I try to pass the function as parameter
let g f (x,y) = (f x, f y)
g id ( 1, '2')
it fails because it takes the version f < int > and it tries to apply it twice.
I've found a workaround but it forces me to write twice the function I'm passing:
let g f1 f2 (x,y) = (f1 x, f2 y)
g id id ( 1, '2')
This is the second time I face this problem.
Why it behaves this way, it's not supposed to be the same if the function is a local value or if it's passed as parameter?
Is there a way to do this without duplicating the function?
A hack, maybe using explicit type constraints, inline magic, quotations?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…