From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 6D8B07FADC for ; Thu, 6 Nov 2014 18:53:09 +0100 (CET) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of r.wobben@home.nl) identity=pra; client-ip=212.54.42.168; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="r.wobben@home.nl"; x-sender="r.wobben@home.nl"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of r.wobben@home.nl) identity=mailfrom; client-ip=212.54.42.168; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="r.wobben@home.nl"; x-sender="r.wobben@home.nl"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@smtpq5.tb.mail.iss.as9143.net) identity=helo; client-ip=212.54.42.168; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="r.wobben@home.nl"; x-sender="postmaster@smtpq5.tb.mail.iss.as9143.net"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AigBANG0W1TUNiqonGdsb2JhbABb11N9FgEBAQEBEQEBAQEBBg0JCRQuhDBRPRYYAwIBAgFYCAEBiEGqNKU8kS6ENQWTMIpkh3aQNoImgzYBAQE X-IPAS-Result: AigBANG0W1TUNiqonGdsb2JhbABb11N9FgEBAQEBEQEBAQEBBg0JCRQuhDBRPRYYAwIBAgFYCAEBiEGqNKU8kS6ENQWTMIpkh3aQNoImgzYBAQE X-IronPort-AV: E=Sophos;i="5.07,327,1413237600"; d="scan'208,217";a="86744985" Received: from smtpq5.tb.mail.iss.as9143.net ([212.54.42.168]) by mail3-smtp-sop.national.inria.fr with ESMTP; 06 Nov 2014 18:53:08 +0100 Received: from [212.54.42.137] (helo=smtp6.tb.mail.iss.as9143.net) by smtpq5.tb.mail.iss.as9143.net with esmtp (Exim 4.76) (envelope-from ) id 1XmRF5-0005K2-JK for caml-list@inria.fr; Thu, 06 Nov 2014 18:53:07 +0100 Received: from 524acd6d.cm-4-3d.dynamic.ziggo.nl ([82.74.205.109] helo=[192.168.0.100]) by smtp6.tb.mail.iss.as9143.net with esmtp (Exim 4.76) (envelope-from ) id 1XmRF5-00009I-5i for caml-list@inria.fr; Thu, 06 Nov 2014 18:53:07 +0100 Message-ID: <545BB589.6060805@home.nl> Date: Thu, 06 Nov 2014 18:53:13 +0100 From: Roelof Wobben User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: caml-list@inria.fr Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Ziggo-spambar: ---- X-Ziggo-spamscore: -4.2 X-Ziggo-spamreport: ALL_TRUSTED=-1,BAYES_00=-1.9,CM_META_TB_NOARR=0.5,HTML_MESSAGE=0.001,MIME_HTML_ONLY=0.001,PROLO_TRUST_RDNS=-3,RDNS_DYNAMIC=0.982,TO_NO_BRKTS_HTML_ONLY=0.199 X-Ziggo-Spam-Status: No X-Spam-Flag: No Subject: [Caml-list] chapter 4 confusion 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