I'm starting to sound like a seller :), but FSharpx has a List.lift2
function that does this (it is parameterized by a function similar to Haskell liftM2
).
So, with FSharpx it let prod = List.lift2 tuple2 xList yList
( tuple2
is a tuple constructor also included in FSharpx)
EDIT: just in case, I would like to point out that I do not propose to get FSharpx dependency just for this ... of course, you could just use list comprehension or even just define lift2 and tuple2 yourself, they are trivial:
let inline lift2 f (l1: _ list) (l2: _ list) = [ for i in l1 do for j in l2 do yield fij ] let inline tuple2 ab = a,b
FSharpx has many built-in goodies like this one.
source share