From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=AWL,HTML_MESSAGE,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 84D28BC0A for ; Thu, 15 Mar 2007 04:21:06 +0100 (CET) Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.175]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l2F3L5Qd019801 for ; Thu, 15 Mar 2007 04:21:06 +0100 Received: by ug-out-1314.google.com with SMTP id k3so150533ugf for ; Wed, 14 Mar 2007 20:21:05 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=fo7+d1ANkuNdszfQH3Oj1DiHe0tVwr4pneat9Mn5PYYIE9QrLM8RoRyYu5f447n4upZU4Xuv9LOvYsYEk+NFvTXYeBVvfHRku3BlDsayWY30OXdF+rKqkOoqOzxXD/aYdh6Uqr8mvRZbj7TXIe77qBulemvDUaWK52euf8b4ERc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=VCfsjXC0rtM8uG6znyPH3kaL6lH5TxquXRXEJNPkSWnDB3uxcBTcn2yf8da9XM4p48gvyrSaka1rkVJBTsSRAs6GsE5YJTti4a9N04P9u+yTfAZrFyxaGkKP5Y/KIpDp1TXnQoYlVcH+Hfcm+ZhLqENHCTj/UesfhKKn11iAaGY= Received: by 10.78.39.16 with SMTP id m16mr84896hum.1173928865347; Wed, 14 Mar 2007 20:21:05 -0700 (PDT) Received: by 10.82.100.16 with HTTP; Wed, 14 Mar 2007 20:21:05 -0700 (PDT) Message-ID: Date: Thu, 15 Mar 2007 04:21:05 +0100 From: Tom To: ian Subject: Re: [Caml-list] Style and organization of code Cc: caml-list@inria.fr In-Reply-To: <45F87661.4020504@softhome.net> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_63043_14249122.1173928865303" References: <45F87661.4020504@softhome.net> X-j-chkmail-Score: MSGID : 45F8BBA1.001 on discorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at discorde with ID 45F8BBA1.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 ocaml:01 underscores:01 compiler:01 mli:01 sig:01 struct:01 compiler:01 mli:01 underscores:01 sig:01 struct:01 fist:98 softhome:98 instinct:98 X-Attachments: cset="UTF-8" cset="UTF-8" ------=_Part_63043_14249122.1173928865303 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 14/03/07, ian wrote: > > I'm looking for a guidebook or just some rules of thumb on how to organize > my > OCaml code. > > One example: > > Say I have a function called "solveHardProblem". So, this is the first place for change. OCaml functions, values, types, and exceptions are usually not named lowerUpperCase, but words_with_underscores - it is somewhat disfunctional for us coming from "other" parts of the world (typing _ includes pressing the Shift key) but so is typing uppercase letter - there are no other alternatives. Anyways, better stick to the convention. solveHardProblem relies on > several helper functions, which are not going to be useful to any other > functions in the program. So, my first instinct would be to define all > the > helpers using let blocks within the definition of solveHardProblem. > > But that would make the definition of solveHardProblem really long -- > several > screens of text -- which I've been taught to avoid. Is it wrong to use a > module > to hide those functions if the module signature will contain only that of > solveHardProblem? No. And say you DO choose to use a module... The OCaml documentation says that > the > compiler can automatically infer the signature without the need to create > a .mli > file for it. Does anyone actually use that feature in practice, or is > creating > a sig hard-wired to the act of creating a struct? Hm... well... I mean, the compiler can actually infer things for you, but this simply means that you don't NEED to include a signature - it's not a compile time error if you omit it. But the comiler will assume that you want all the values (including functions) and types from this module to be exported. So .mli signatures are actually used for limiting exports. Exactly what you're trying to do. Or you can simply define helper functions, and never use them. - Tom ------=_Part_63043_14249122.1173928865303 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline

On 14/03/07, ian <fist_187@softhome.net> wrote:
I'm looking for a guidebook or just some rules of thumb on how to organize my
OCaml code.

One example:

Say I have a function called "solveHardProblem".

So, this is the first place for change. OCaml functions, values, types, and exceptions are usually not named lowerUpperCase, but words_with_underscores - it is somewhat disfunctional for us coming from "other" parts of the world (typing _ includes pressing the Shift key) but so is typing uppercase letter - there are no other alternatives. Anyways, better stick to the convention.

solveHardProblem relies on
several helper functions, which are not going to be useful to any other
functions in the program.  So, my first instinct would be to define all the
helpers using let blocks within the definition of solveHardProblem.

But that would make the definition of solveHardProblem really long -- several
screens of text -- which I've been taught to avoid.  Is it wrong to use a module
to hide those functions if the module signature will contain only that of
solveHardProblem?

No. 

And say you DO choose to use a module...  The OCaml documentation says that the
compiler can automatically infer the signature without the need to create a .mli
file for it.  Does anyone actually use that feature in practice, or is creating
a sig hard-wired to the act of creating a struct?

Hm... well... I mean, the compiler can actually infer things for you, but this simply means that you don't NEED to include a signature - it's not a compile time error if you omit it. But the comiler will assume that you want all the values (including functions) and types from this module to be exported. So .mli signatures are actually used for limiting exports. Exactly what you're trying to do.

Or you can simply define helper functions, and never use them.

- Tom
------=_Part_63043_14249122.1173928865303--