4
私はOCamlで単純な範囲関数を実装しようとしています。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
これは明らかに最後の定義がうまくいきません。複数のアーリー関数を定義する方法はありますか?
しないでください。オプションの引数を使用する –