Ocaml 整数型n型
我正在研究一个模块,该模块涉及一组自然参数 数字。因此,我需要对integer类型的一些n进行建模。我怎么能 去吧 例如,从1开始连续递增的i序列的i之和= n(n+1)/2Ocaml 整数型n型,ocaml,Ocaml,我正在研究一个模块,该模块涉及一组自然参数 数字。因此,我需要对integer类型的一些n进行建模。我怎么能 去吧 例如,从1开始连续递增的i序列的i之和= n(n+1)/2 我如何在这里建模n?要求我们应该能够使用n作为整数。我想我明白了 type element_i = N of nativeint | CNN of nativeint*nativeint (* element_i can be an integer or a*n+b represented as (a,b)) le
我如何在这里建模n?要求我们应该能够使用n作为整数。我想我明白了
type element_i = N of nativeint | CNN of nativeint*nativeint
(* element_i can be an integer or a*n+b represented as (a,b))
let to_string_i e = match e with N z -> "%d" z | CNN c -> " (%d xn + %d) " (fst c) (snd c)
let plus_i a b =
match (a,b) with
| (N a1,N b1) -> N (a1 + b1)
| (N a1,CNN b1) -> CNN (fst b1, (snd b1) + a1)
| (CNN a1,N b1) -> CNN (fst a1, (snd a1) + b1)
let times_i a b =
match (a,b) with
| (N a1,N b1) -> N (a1 * b1)
| (N a1,CNN b1) -> CNN ((fst b1) * a1, (snd b1) * a1)
| (CNN a1,N b1) -> CNN ((fst a1)* b1, (snd a1) * b1)
你的要求是什么?int或大型int库有什么问题?