caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Style question
@ 2001-09-09 21:00 Brian Rogoff
  2001-09-11  9:59 ` Andreas Rossberg
  0 siblings, 1 reply; 12+ messages in thread
From: Brian Rogoff @ 2001-09-09 21:00 UTC (permalink / raw)
  To: caml-list

I've been hacking a bit with SML lately and I notice that a lot of
SML code uses the local <private fundefs> in <public fundefs> end
construct. Do SMLers who like this and wind up writing OCaml use
modules for this? Something like

module SomeDefs : sig
  <public fundecls>
end = struct
  <private fundefs>
  <public fundefs>
end
(* <open or include> SomeDefs, or just use SomeDefs.f ... *)

or is the slight extra verbosity a disincentive?

It seems to me that all of the uses of local in SML can be handled can be
handled by the module system in OCaml, and I don't even find the unsugared
forms to be bad at all.

-- Brian


-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Caml-list] Style question
  2001-09-09 21:00 [Caml-list] Style question Brian Rogoff
@ 2001-09-11  9:59 ` Andreas Rossberg
  2001-09-11 10:55   ` Sven
  2001-09-11 18:11   ` Brian Rogoff
  0 siblings, 2 replies; 12+ messages in thread
From: Andreas Rossberg @ 2001-09-11  9:59 UTC (permalink / raw)
  To: caml-list

Brian Rogoff wrote:
> 
> It seems to me that all of the uses of local in SML can be handled can be
> handled by the module system in OCaml, and I don't even find the unsugared
> forms to be bad at all.

It is not exactly sugar since you can express things with local that you
cannot with signatures - but all of them are pretty useless. My personal
opinion is that using modules is preferable even in SML, its local being
an anachronism from the pre-module days, just like abstype. I almost
never use it. It only comes in handy in conjunction with open:

	local open M in
	...
	end

Of course, in OCaml this is solved by having open vs. include.

	- Andreas

-- 
Andreas Rossberg, rossberg@ps.uni-sb.de

"Computer games don't affect kids; I mean if Pac Man affected us
 as kids, we would all be running around in darkened rooms, munching
 magic pills, and listening to repetitive electronic music."
 - Kristian Wilson, Nintendo Inc.
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Caml-list] Style question
  2001-09-11  9:59 ` Andreas Rossberg
@ 2001-09-11 10:55   ` Sven
  2001-09-11 12:08     ` Andreas Rossberg
  2001-09-11 18:11   ` Brian Rogoff
  1 sibling, 1 reply; 12+ messages in thread
From: Sven @ 2001-09-11 10:55 UTC (permalink / raw)
  To: Andreas Rossberg; +Cc: caml-list

On Tue, Sep 11, 2001 at 11:59:18AM +0200, Andreas Rossberg wrote:
> Brian Rogoff wrote:
> > 
> > It seems to me that all of the uses of local in SML can be handled can be
> > handled by the module system in OCaml, and I don't even find the unsugared
> > forms to be bad at all.
> 
> It is not exactly sugar since you can express things with local that you
> cannot with signatures - but all of them are pretty useless. My personal
> opinion is that using modules is preferable even in SML, its local being
> an anachronism from the pre-module days, just like abstype. I almost
> never use it. It only comes in handy in conjunction with open:
> 
> 	local open M in
> 	...
> 	end
> 
> Of course, in OCaml this is solved by having open vs. include.

Also, would not :

let module = struct ... end in 

be another solution for it, maybe in conjunction with the open syntax ?

Friendly,

Sven Luther
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Caml-list] Style question
  2001-09-11 10:55   ` Sven
@ 2001-09-11 12:08     ` Andreas Rossberg
  2001-09-11 12:16       ` Sven
  0 siblings, 1 reply; 12+ messages in thread
From: Andreas Rossberg @ 2001-09-11 12:08 UTC (permalink / raw)
  To: caml-list; +Cc: Sven

Sven wrote:
> 
> >       local open M in
> >       ...
> >       end
> >
> > Of course, in OCaml this is solved by having open vs. include.
> 
> Also, would not :
> 
> let module = struct ... end in
> 
> be another solution for it, maybe in conjunction with the open syntax ?

Not sure, since I don't understand your code snippet, or how it is
related to local or open. Could you clarify a bit?

Anyway, there are of course several ways to rewrite SML's local. If it
involves only core declarations and the body consists of only one
function you might transform it into a let, although I think that is
usually not a good idea. On structure level the most faithful
translation to OCaml is:

module Local = struct (* Prefix *) module Body = struct (* Body *) end
end
include Local.Body

But this is quite unreadable and introduces the auxiliary module name
Local (which would not be necessary if OCaml supported let as module
expressions). In general relying on signature constraints is by far the
best solution and works for all sane uses of local.

	- Andreas

-- 
Andreas Rossberg, rossberg@ps.uni-sb.de

"Computer games don't affect kids; I mean if Pac Man affected us
 as kids, we would all be running around in darkened rooms, munching
 magic pills, and listening to repetitive electronic music."
 - Kristian Wilson, Nintendo Inc.
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Caml-list] Style question
  2001-09-11 12:08     ` Andreas Rossberg
@ 2001-09-11 12:16       ` Sven
  2001-09-11 14:28         ` Brian Rogoff
  2001-09-11 14:29         ` Andreas Rossberg
  0 siblings, 2 replies; 12+ messages in thread
From: Sven @ 2001-09-11 12:16 UTC (permalink / raw)
  To: Andreas Rossberg; +Cc: caml-list

On Tue, Sep 11, 2001 at 02:08:32PM +0200, Andreas Rossberg wrote:
> Sven wrote:
> > 
> > >       local open M in
> > >       ...
> > >       end
> > >
> > > Of course, in OCaml this is solved by having open vs. include.
> > 
> > Also, would not :
> > 
> > let module = struct ... end in
> > 
> > be another solution for it, maybe in conjunction with the open syntax ?
> 
> Not sure, since I don't understand your code snippet, or how it is
> related to local or open. Could you clarify a bit?

Well, consider :

let module M = struct let f x = x * x end in M.f 5 ;;

Sure, you still have to access f trough M., but you could imagine something
with the open/include directive. Not sure if it is possible already to do a
local open, but i think it was already discussed in the past. Consider :

let module M = struct let f x = x * x end in let open M in f 5 ;;

not sure if that is what you wanted though, ...


Friendly,

Sven Luther
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Caml-list] Style question
  2001-09-11 12:16       ` Sven
@ 2001-09-11 14:28         ` Brian Rogoff
  2001-09-11 14:29         ` Andreas Rossberg
  1 sibling, 0 replies; 12+ messages in thread
From: Brian Rogoff @ 2001-09-11 14:28 UTC (permalink / raw)
  To: Sven; +Cc: Andreas Rossberg, caml-list

On Tue, 11 Sep 2001, Sven wrote:
> On Tue, Sep 11, 2001 at 02:08:32PM +0200, Andreas Rossberg wrote:
> > Sven wrote:
> > >
> > > >       local open M in
> > > >       ...
> > > >       end
> > > >
> > > > Of course, in OCaml this is solved by having open vs. include.
> > >
> > > Also, would not :
> > >
> > > let module = struct ... end in
> > >
> > > be another solution for it, maybe in conjunction with the open syntax ?
> >
> > Not sure, since I don't understand your code snippet, or how it is
> > related to local or open. Could you clarify a bit?

let module = struct open M <do stuff with opened> ... let f = ... end
in f ...

This pretty much gives you local open, with very little verbosity. I don't
even think the sugar is needed.

> Well, consider :
>
> let module M = struct let f x = x * x end in M.f 5 ;;
>
> Sure, you still have to access f trough M., but you could imagine something
> with the open/include directive. Not sure if it is possible already to do a
> local open, but i think it was already discussed in the past. Consider :

The solution is just to do the open in the local module, and everything in
the scope of that module can use opened identifiers.

-- Brian


-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Caml-list] Style question
  2001-09-11 12:16       ` Sven
  2001-09-11 14:28         ` Brian Rogoff
@ 2001-09-11 14:29         ` Andreas Rossberg
  1 sibling, 0 replies; 12+ messages in thread
From: Andreas Rossberg @ 2001-09-11 14:29 UTC (permalink / raw)
  To: Sven; +Cc: caml-list

Sven wrote:
> 
> > Not sure, since I don't understand your code snippet, or how it is
> > related to local or open. Could you clarify a bit?
> 
> Well, consider :
> 
> let module M = struct let f x = x * x end in M.f 5 ;;
> 
> Sure, you still have to access f trough M., but you could imagine something
> with the open/include directive.

I suspect you are mixing up issues. Brian asked what the best OCaml
translation of SML's "local" construct would be. In SML "local" allows
to limit the scope of declarations. Unlike "let", its body is not an
expression but again a sequence of declarations, so that the whole
construct is a declaration. I argued that the one of the few real uses
of that construct is to restrict the scope of an "open" declaration in
SML.

So we were not discussing how to encode something like "let open M in
exp" in OCaml (although that also might be an issue when translating SML
to OCaml). That is relatively easy with "let module" and has been
discussed here before, IIRC:

	let module Aux = struct open M val body = exp end in Aux.body

Was that what you were aiming at?

	- Andreas

-- 
Andreas Rossberg, rossberg@ps.uni-sb.de

"Computer games don't affect kids; I mean if Pac Man affected us
 as kids, we would all be running around in darkened rooms, munching
 magic pills, and listening to repetitive electronic music."
 - Kristian Wilson, Nintendo Inc.
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Caml-list] Style question
  2001-09-11  9:59 ` Andreas Rossberg
  2001-09-11 10:55   ` Sven
@ 2001-09-11 18:11   ` Brian Rogoff
  2001-09-12  9:03     ` Andreas Rossberg
  1 sibling, 1 reply; 12+ messages in thread
From: Brian Rogoff @ 2001-09-11 18:11 UTC (permalink / raw)
  To: Andreas Rossberg; +Cc: caml-list

On Tue, 11 Sep 2001, Andreas Rossberg wrote:
> Brian Rogoff wrote:
> >
> > It seems to me that all of the uses of local in SML can be handled can be
> > handled by the module system in OCaml, and I don't even find the unsugared
> > forms to be bad at all.
>
> It is not exactly sugar since you can express things with local that you
> cannot with signatures - but all of them are pretty useless.

I've only seen some of the more bizarre uses (like coding dynamics using
"polymorphic" local exceptions) as stupid pet tricks. But I've read lot's
of SML code that makes heavy use of local to hide function names. I almost
never see an abstype.

> My personal opinion is that using modules is preferable even in SML,
> its local being an anachronism from the pre-module days, just like
> abstype. I almost never use it.

Good! Your code should port easily then.

> It only comes in handy in conjunction with open:

Right, but I assume you know the workaround, since you decribe it in a
followup, and I assume you've read this page

  http://www.ps.uni-sb.de/~rossberg/SMLvsOcaml.html


I just wish the author would update the section on localdecs to mention
using modules instead of local open :-)

-- Brian


http://www.ps.uni-sb.de/~rossberg/SMLvsOcaml.html#localdecs

>
> 	local open M in
> 	...
> 	end
>
> Of course, in OCaml this is solved by having open vs. include.
>
> 	- Andreas
>
> --
> Andreas Rossberg, rossberg@ps.uni-sb.de
>
> "Computer games don't affect kids; I mean if Pac Man affected us
>  as kids, we would all be running around in darkened rooms, munching
>  magic pills, and listening to repetitive electronic music."
>  - Kristian Wilson, Nintendo Inc.
> -------------------
> Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
> To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr
>

-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Caml-list] Style question
  2001-09-11 18:11   ` Brian Rogoff
@ 2001-09-12  9:03     ` Andreas Rossberg
  0 siblings, 0 replies; 12+ messages in thread
From: Andreas Rossberg @ 2001-09-12  9:03 UTC (permalink / raw)
  To: Brian Rogoff; +Cc: caml-list

Brian Rogoff wrote:
> 
> Right, but I assume you know the workaround, since you decribe it in a
> followup, and I assume you've read this page
> 
>   http://www.ps.uni-sb.de/~rossberg/SMLvsOcaml.html
> 
> I just wish the author would update the section on localdecs to mention
> using modules instead of local open :-)

Mh, it seems to me he already does hint at the "let module" workaround
in that section...?

-- 
Andreas Rossberg, rossberg@ps.uni-sb.de

"Computer games don't affect kids; I mean if Pac Man affected us
 as kids, we would all be running around in darkened rooms, munching
 magic pills, and listening to repetitive electronic music."
 - Kristian Wilson, Nintendo Inc.
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [Caml-list] Style question
@ 2001-09-12 10:24 Dave Berry
  0 siblings, 0 replies; 12+ messages in thread
From: Dave Berry @ 2001-09-12 10:24 UTC (permalink / raw)
  To: Brian Rogoff, caml-list

It's certainly not a style I would consider using in SML itself.  I
haven't written enough OCaml code to say how I would write this in
OCaml.

My preferred solution would be simply to allow a "local" prefix to any
declaration, which would indicate that that entity would not be visible
outside the current scope.

Dave.

-----Original Message-----
From: Brian Rogoff [mailto:bpr@best.com]
Sent: 09 September 2001 22:00
To: caml-list@inria.fr
Subject: [Caml-list] Style question


I've been hacking a bit with SML lately and I notice that a lot of
SML code uses the local <private fundefs> in <public fundefs> end
construct. Do SMLers who like this and wind up writing OCaml use
modules for this? Something like

module SomeDefs : sig
  <public fundecls>
end = struct
  <private fundefs>
  <public fundefs>
end
(* <open or include> SomeDefs, or just use SomeDefs.f ... *)

or is the slight extra verbosity a disincentive?

It seems to me that all of the uses of local in SML can be handled can
be
handled by the module system in OCaml, and I don't even find the
unsugared
forms to be bad at all.

-- Brian


-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ:
http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives:
http://caml.inria.fr
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Caml-list] Style question
  2001-09-11 18:58 Krishnaswami, Neel
@ 2001-09-12  9:14 ` Andreas Rossberg
  0 siblings, 0 replies; 12+ messages in thread
From: Andreas Rossberg @ 2001-09-12  9:14 UTC (permalink / raw)
  To: Krishnaswami, Neel; +Cc: caml-list

"Krishnaswami, Neel" wrote:
> 
> >   http://www.ps.uni-sb.de/~rossberg/SMLvsOcaml.html
> >
> > I just wish the author would update the section on localdecs
> > to mention using modules instead of local open :-)
> 
> Is this a subtle joke that I'm missing? Andreas Rossberg *wrote* that
> page!

Ah, that's why it looked so familar! :-)

But seriously, please note that most of the credit for that page should
go to Jens Olsson who had the idea and wrote the original version.

And now I assume we should no longer tax the patience of the Caml users
with discussions about SML related topics. ;-)

Best regards,

	- Andreas

-- 
Andreas Rossberg, rossberg@ps.uni-sb.de

"Computer games don't affect kids; I mean if Pac Man affected us
 as kids, we would all be running around in darkened rooms, munching
 magic pills, and listening to repetitive electronic music."
 - Kristian Wilson, Nintendo Inc.
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Caml-list] Style question
@ 2001-09-11 18:58 Krishnaswami, Neel
  2001-09-12  9:14 ` Andreas Rossberg
  0 siblings, 1 reply; 12+ messages in thread
From: Krishnaswami, Neel @ 2001-09-11 18:58 UTC (permalink / raw)
  To: caml-list

Brian Rogoff [mailto:bpr@best.com] wrote:
> On Tue, 11 Sep 2001, Andreas Rossberg wrote:
> > 
> > My personal opinion is that using modules is preferable even in SML,
> > its local being an anachronism from the pre-module days, just like
> > abstype. I almost never use it. It only comes in handy in conjunction 
> > with open:
> 
> Right, but I assume you know the workaround, since you decribe it in a
> followup, and I assume you've read this page
> 
>   http://www.ps.uni-sb.de/~rossberg/SMLvsOcaml.html
> 
> I just wish the author would update the section on localdecs 
> to mention using modules instead of local open :-)

Is this a subtle joke that I'm missing? Andreas Rossberg *wrote* that 
page!

--
Neel Krishnaswami
neelk@cswcasa.com
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2001-09-12 10:25 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-09 21:00 [Caml-list] Style question Brian Rogoff
2001-09-11  9:59 ` Andreas Rossberg
2001-09-11 10:55   ` Sven
2001-09-11 12:08     ` Andreas Rossberg
2001-09-11 12:16       ` Sven
2001-09-11 14:28         ` Brian Rogoff
2001-09-11 14:29         ` Andreas Rossberg
2001-09-11 18:11   ` Brian Rogoff
2001-09-12  9:03     ` Andreas Rossberg
2001-09-11 18:58 Krishnaswami, Neel
2001-09-12  9:14 ` Andreas Rossberg
2001-09-12 10:24 Dave Berry

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).