4
OCaml에서 간단한 범위 함수를 구현하려고하는데 다른 arity 호출에 대해 어떻게 할 수 있는지 궁금합니다.OCaml에서 다중 배열 함수를 정의하는 올바른 방법은 무엇입니까?
let range_aux ~start ~stop ~step =
let rec aux start stop step acc =
match (start, stop, step, acc) with
| (start,stop,step,acc) when start = stop -> List.rev acc
| (start,stop,step,acc) -> aux (start + step) stop step (start :: acc) in
aux start stop step []
let range ~start ~stop ~step = range_aux ~start ~stop ~step
let range ~stop ~step = range_aux ~start:0 ~stop ~step
let range ~stop = range_aux ~start:0 ~stop ~step:1
분명히 마지막 정의가 적용되지 않습니다. 여러 가지 자질 함수를 정의 할 수있는 방법이 있습니까?
하지 마십시오. 선택적 인수 사용 –