我有一个接受元组的结构构造函数,但我需要用两个数组来构造它。我当前的解决方案在尝试映射函数时遇到了问题。柯里化消失了。希望有一种替代方法可以做到这一点。
type Example =
struct
val X : int
val Y : int
new(x: int, y: int) = { X = x; Y = y} // constructor is (int * int -> Example)
end
let foo = fun x y -> Example(x, y) // to curry; foo is now (int -> int -> Example)
let bar = Array.map foo // oh no; it changed to (int array-> (int -> Example) array)
// how can it be (int array -> int array -> Example array) instead?
// this is my imagined implementation
let a = seq{0 .. 100} // these sequences are filler for this demonstration
let b = seq{0 .. 100}
let myArray = bar a b // where myArray is (Example array)
我找到了。解决这个问题的方法是
map2
。
将
let bar = Array.map foo
交换为 let bar = Array.map2 foo
允许使用 let myArray = bar a b
,其中 bar
是 int array -> int array -> Example array