chapter 4 confusion
| Newsgroups | gmane.comp.lang.ocaml.beginners |
|---|---|
| Message-ID | <[email protected]> |
Hello, Chapter 4 of RealWorldOcaml begins with this programm : open Core.Std let build_counts () = In_channel.fold_lines stdin ~init:[] ~f:(fun counts line -> let count = match List.Assoc.find counts line with | None -> 0 | Some x -> x in List.Assoc.add counts line (count + 1) ) let () = build_counts () |> List.sort ~cmp:(fun (_,x) (_,y) -> Int.descending x y) |> (fun l -> List.take l 10) |> List.iter ~f:(fun (line,count) -> printf "%3d: %s\n" count line) But I do not really understand what each line does 1) What means ln.channel.fold_lines stdin ~init part means ? 2) What does the |> does exactly. I know chapter 2 does explain it a little bit but it's still not clear to me 3) What does ~cmp mean. Roelof __._,_.___ ---------- Posted by: Roelof Wobben <[email protected]> ---------- Reply via web post • Reply to sender • Reply to group • Start a New Topic • Messages in this topic (1) Archives up to December 31, 2011 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners The archives of the very official ocaml list (the seniors' one) can be found at http://caml.inria.fr Attachments are banned and you're asked to be polite, avoid flames etc. Visit Your Group - New Members 2 https://groups.yahoo.com/neo;_ylc=X3oDMTJkajZhc2JmBF9TAzk3NDc2NTkwBGdycElkAzQ5OTkxOTQEZ3Jwc3BJZAMxNzA1MDA2NzY0BHNlYwNmdHIEc2xrA2dmcARzdGltZQMxNDE1MjYwMTg1 • Privacy • Unsubscribe • Terms of Use . __,_._,___