-
Notifications
You must be signed in to change notification settings - Fork 44
Open
Labels
Description
Signature is:
val traverse : ('a -> 'b Gen.t) -> 'a list -> 'b list Gen.tImplementation proposition:
let rec traverse gen = function
| [] -> pure []
| x :: xs ->
let* x = gen x and* xs = traverse gen xs in
pure (x :: xs)Or in short:
let traverse gen xs =
let cons_f x xs = List.cons <$> gen x <*> xs in
List.fold_right cons_f xs (pure [])I had been in need for this particular combinator in a relatively specific case: when generating well-typed terms of a language with n-ary functions. The term generator takes a type from the object language, and when I wanted to generate a function call, I needed to generate a list of terms from a list of types from the object language.
But maybe there are other use-cases?
jmid