String grammar generation could be improved and made easier when concatenating a list of generator
Sentence = Subject Verb Location
...
in order to make my sentence i have to do something like:
map [subj; verb; loc] (fun subj verb loc -> subj ^ verb ^ loc)
or map [subj; verb; loc] (fun subj verb loc -> String.concat separator [subj; verb; loc]) if i need a separator. The more generators you want to concatenate the more unreadable it gets !
The concatenation isn't well supported, this would be great for generating grammar such as http.
I suggest adding functions for strings
(* concatenate a List of string gen inserting the separator string sep between each *)
let concat_gen_list sep l =
List.fold_left (fun acc e ->
map [acc; sep; e] (fun acc sep e -> acc ^ e ^ sep)
) empty l
(* Concatenate a Crowbar.list equivalent String.concat on Crowbar.list gen *)
let concat_list_gen sep l =
map [sep; l] String.concat
We could even improve the concept by adding the operator as an argument
(* concatenate a List of 'a gen inserting the separator sep between each *)
let concat_gen_list sep l op =
List.fold_left (fun acc e ->
map [acc; sep; e] (fun acc sep e -> op (op acc e) sep )
) empty l
String grammar generation could be improved and made easier when concatenating a list of generator
in order to make my sentence i have to do something like:
map [subj; verb; loc] (fun subj verb loc -> subj ^ verb ^ loc)
ormap [subj; verb; loc] (fun subj verb loc -> String.concat separator [subj; verb; loc])
if i need a separator. The more generators you want to concatenate the more unreadable it gets !The concatenation isn't well supported, this would be great for generating grammar such as http. I suggest adding functions for strings
We could even improve the concept by adding the operator as an argument
This is just an idea, PR to come if you approve !