caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Yotam Barnoy <yotambarnoy@gmail.com>
To: Hendrik Boom <hendrik@topoi.pooq.com>
Cc: Ocaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Warnings opening modules (was: why is building ocaml hard?)
Date: Fri, 15 Jul 2016 12:57:50 -0400	[thread overview]
Message-ID: <CAN6ygO=cogFgUj9oADT6Cy-LEiZ7B=PYhpyufzcXEoawaYUhWg@mail.gmail.com> (raw)
In-Reply-To: <20160715161308.GB30333@topoi.pooq.com>

The problem seems to stem from the fact that the same open statements
which we use to import code (and which are available in every
language) are also used as part of OCaml's super-flexible module
system. This makes it hard to come up with easy, simple shortcuts for
functionality available in other languages, because it needs to fit in
the far more complex general module language.

In haskell, I can just say 'import A (foo, bar, baz, t)' to limit
exactly what I want to import. This is because haskell has a
half-baked module system that isn't nearly as powerful as OCaml's,
which allows it to create syntax that doesn't need to go anywhere but
at the toplevel.

We need this functionality in OCaml, but the closest thing is to say
'include struct let foo = A.foo let bar = A.bar let baz = A.baz type t
= A.t end'

I'm not sure if there's a performance cost to doing things this way,
but it's also incredibly verbose and therefore nearly unusable in the
general case simply because it needs to fit into the general module
language.

Additionally, haskell handles module hierarchies gracefully (tying
them to the OS filesystem), while OCaml is stuck with a flat
hierarchy, needing modular tricks to get the same hierarchies that
other languages have naturally (via specialized syntax).

The generality of OCaml's module language is killing its usability for
the most common cases.

On Fri, Jul 15, 2016 at 12:13 PM, Hendrik Boom <hendrik@topoi.pooq.com> wrote:
> On Fri, Jul 15, 2016 at 10:52:38AM +0100, David Allsopp wrote:
>> Goswin von Brederlow wrote:
>>
>> I don't follow what you mean - what I propose changing is that [open Util]
>> would cause a warning and eventually, in some future version of OCaml, be
>> rejected by the compiler. The problem it would solve is that
>> ocamldep/whatever knows that open Foo always refers to a toplevel (or fully
>> qualified) module path.
>>
>> > A (for me) more common code would be:
>> >
>> >     open ReallyCoolLibraryPack
>> >     (* myriad more open statements *)
>> >
>> >     Util.foo bla baz
>> >     module Bla = Util.MAKE(M : FOOABLE)
>> >
>> > You still get the same dependency on ReallyCoolLibraryPack.Util,
>> > ReallyCoolLibraryPack.Util.MAKE, ReallyCoolLibraryPack.FOOABLE, ...
>> > without successive opens.
>>
>> Indeed, that's my preference, although I'm stupidly picky and actually
>> prefer to write:
>>
>> module Util = ReallyCoolLibraryPack.Util
>>
>> but that comes under my list of "strange habits which normal people don't
>> agree with" :o) I'm allergic to anything which involves a wildcard ([open
>> ReallyCoolLibraryPack] being rather too like writing [import
>> ReallyCoolLibraryPack.*;])
>
> And that's a real problem -- that fact that openning a module can fill
> the namespace with lots of stray identifiers, which the user does not
> control.
>
> It may reduce the amount of code you have to write.
>
> But it makes the code unstable in the long run, and it makes it hard to
> read.  The naive reader will encounter identifiers and have no idea
> where to look for their definitions.
>
> It's not just a problem with modules that define modules.  It'a a
> problem with modules that define anything.
>
> To alleviate this, either specify explicitly what names you are
> accepting definitions of when you open a module, or, after you open a
> module, mention the module name very time you use one if its defined
> names, as, Module.name instead of just name.
>
> And make the compiler check this.  Withiut a constraint like this, I
> find much OCaml code incomprehensible.
>
> Or is there some kind of code browsing tool that explicates all this?
>
> -- hendrik
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs

  reply	other threads:[~2016-07-15 16:58 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-10 11:57 David Allsopp
2016-07-10 19:45 ` Gerd Stolpmann
2016-07-13 12:08   ` David Allsopp
2016-07-13 12:20     ` Gerd Stolpmann
2016-07-13 12:30       ` David Allsopp
2016-07-14  9:03     ` Goswin von Brederlow
2016-07-15  9:52       ` David Allsopp
2016-07-15 16:13         ` Hendrik Boom
2016-07-15 16:57           ` Yotam Barnoy [this message]
2016-07-15 18:09             ` Jeremy Yallop
2016-07-15 18:26               ` Hendrik Boom
2016-07-15 18:58               ` Yotam Barnoy
2016-07-15 19:26                 ` Hezekiah M. Carty
2016-07-15 19:42                   ` Yotam Barnoy
2016-07-15 19:52                     ` Jeremy Yallop
2016-07-15 20:25                       ` Yotam Barnoy
2016-07-15 18:50             ` Alain Frisch
2016-07-15 19:44               ` Hendrik Boom
2016-07-15 17:04           ` Gerd Stolpmann
2016-07-20  7:49             ` Louis Gesbert
2016-07-16  7:40           ` Petter A. Urkedal
2016-07-16  9:58             ` vrotaru.md
2016-07-19 16:37               ` Yotam Barnoy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAN6ygO=cogFgUj9oADT6Cy-LEiZ7B=PYhpyufzcXEoawaYUhWg@mail.gmail.com' \
    --to=yotambarnoy@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=hendrik@topoi.pooq.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).