I'm trying to learn functional programming and having difficulty expressing a file parsing task functionally.Let's say I have a text file with the following format:
val_0: <--- "header"key_0_0 <--- these keys should be set to the "header" or val0key_0_1key_0_2......val_n: ...key_n_m
How can I end up with a hash table with all keys set to their associated value?
EDIT: My solution. Can anyone improve it?
open Core.Stdlet contains s1 s2 = let re = Str.regexp_string s2 in try ignore (Str.search_forward re s1 0); true with Not_found -> falselet read_db f = let tbl = Caml.Hashtbl.create 123456 in let lines = In_channel.read_lines f in let src = ref "" in List.iter ~f:(fun g -> if contains g ":" then src := else Caml.Hashtbl.add tbl g !src) lines; tbl