Hello,
Here another question I asked on the beginners list with no answers.
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