-1
我有一个这个练习的问题!从列表[a1,...,ai,ai + 1,....,an]到列表[ai + 1,...,an,a1,... ai]的OCaml
我的想法是创建两个功能:
- 第一个函数创建列表
[ai + 1, ..., an]
- 第二个功能,作为输入的第一个函数的结果并返回结果:
[ai + 1, ..., an, a1, ..., ai]
问题是我刚开始使用Ocaml进行编程,我不太清楚如何使用它。所以我有一些我不知道如何解决的错误。 我的代码是这样的:
let rec produceprima l i =
let rec produceprima_aux l i acc=
let rec aux l i acc l1 =
match l with
[]-> []
|x::y -> if(acc>i) then aux y i acc+1 [email protected][x]
else aux y i acc+1 l1
in aux l i acc l1
in produceprima_aux l i acc;;
let rec produceseconda l i =
let rec produceseconda_aux l i acc=
let rec aux l i acc l1 =
match l with
[]-> []
|x::y -> if(acc<=i) then aux y i acc+1 [email protected][x]
in aux l i acc l1
in produceseconda_aux l i acc;;
第一功能的错误是:
Error: This expression has type 'a -> 'b list
but an expression was expected of type int
第二个功能,我必须尝试,但肯定是有错误!
非常感谢:D我试试!当然,我会看到教程! –