Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ocaml 如何将多参数函数映射到数字列表_Ocaml - Fatal编程技术网

Ocaml 如何将多参数函数映射到数字列表

Ocaml 如何将多参数函数映射到数字列表,ocaml,Ocaml,所以我试图映射一个函数,它有3个参数,2个是给定的,以及最后一个变量的数字列表。我使用我的地图功能,但我不会工作,我不知道为什么。如果传入的函数有2个参数,则我可以工作。我试图寻找其他解决方案,但没有发现太多我不确定,但我应该递归地尝试吗 let segment (cx,cy) (nx,ny) = let lnf = range (cx+1) nx in let s = slope (cx,cy) (nx,ny) in let y = yintercept (cx,cy)

所以我试图映射一个函数,它有3个参数,2个是给定的,以及最后一个变量的数字列表。我使用我的地图功能,但我不会工作,我不知道为什么。如果传入的函数有2个参数,则我可以工作。我试图寻找其他解决方案,但没有发现太多我不确定,但我应该递归地尝试吗

let segment (cx,cy) (nx,ny) =
    let lnf = range (cx+1) nx in
    let s = slope (cx,cy) (nx,ny) in
    let y = yintercept (cx,cy) in
    map (solve s y) lnf;;

let slope (x1,y1) (x2,y2) : int =
  (y2-y1)/(x2-x1)

let yintercept ((x1,y1):coord) slope: int =
    (y1 - (slope * x1))

let solve (m:int) (b:int) (x:int)=
    (x*m)+b

let rec map: ('a -> 'b)  -> 'a list -> 'b list = fun f l ->
  match l with
  | [] -> []
  | h::t -> f h ::  map f t
在这方面:

let y = yintercept (cx,cy) in
您只需要一个参数就可以调用
yintercept
。但函数需要两个参数。因此,返回值是一个参数的函数。代码的其余部分假定
y
int
(不是函数)