[Solved] Convert a char list list into a char string list in OCAML

Here is a very compact implementation: let to_str_list = List.map (fun cs -> String.concat “” (List.map (String.make 1) cs)) It looks like this when your call it: # to_str_list [[‘h’;’e’;’l’;’l’;’o’];[‘w’;’o’;’r’;’l’;’d’]];; – : string list = [“hello”; “world”] Update If you want to suppress empty strings at the outer level you can do something like this: … Read more

[Solved] OCaml: How can I return the first element of a list and after that remove it from the list?

I think there are a couple of misunderstandings here. First, most types in OCaml are immutable. Unless you use mutable variables you can’t “remove it from the list”, you can only return a version of the list that doesn’t have that first item. If you want to return both things you can achieve that using … Read more

[Solved] Contagion program, Matrices and Syntax issue

= is the structural equality operator. To set an array element you need to use <-. Also, you should almost never use == because it tests for physical equality, i.e. that references point to the same address in memory. For comparing bools it doesn’t strictly matter, because they’re not pointers, but you should get into … Read more