Hi there !
To more deeper the rust language, i've decided to code the List standard library of Ocaml. But I get an issue.
pub fn init<U: Fn(u32) -> T>(length: u32, f: U) -> Self
{
let aux = |i: u32, stackl: Self|
if i == length { stackl }
else { aux(i+1, List::<T>::cons(f(i),stackl)) };
aux(0,Nil)
}
The goal of this function is to return a List<T>
object, which is initialized with [f(0) ; f(1) ; ... ; f(length - 1) ]. I've first tried to define a auxilliary function, but that doesn't capture length
, so i've tried with closure, but I can't do this because the name of the closure isn't known.
How to do this ?
Other little questions : is it possible to make mutually recursive functions and types in Rust ?
Thanks a lot !