caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] use of ";;" when teaching Ocaml
@ 2015-06-22 13:31 Alan Schmitt
  2015-06-22 13:52 ` Ivan Gotovchits
                   ` (4 more replies)
  0 siblings, 5 replies; 29+ messages in thread
From: Alan Schmitt @ 2015-06-22 13:31 UTC (permalink / raw)
  To: OCaml Mailing List

[-- Attachment #1: Type: text/plain, Size: 764 bytes --]

Hello,

In my Ocaml class, I tend to promote the use of ";;" to separate phrases
(I'm basically following
http://ocaml.org/learn/tutorials/structure_of_ocaml_programs.html#Usingandomittingand
although I was not aware of this page when I created the course). My
motivation is to minimize the difference between using the top-level and
writing files.

I am now wondering if this is a good practice. In a nutshell, would you
rather use

#+begin_src ocaml
let x = 12;;
print_endline "Hello World!"
#+end_src

or

#+begin_src ocaml
let x = 12
let () = print_endline "Hello World!"
#+end_src

when teaching Ocaml?

Thanks,

Alan

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7
Weekly CO₂ average (2015-05-30, Mauna Loa Observatory): 403.41 ppm

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

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

* Re: [Caml-list] use of ";;" when teaching Ocaml
  2015-06-22 13:31 [Caml-list] use of ";;" when teaching Ocaml Alan Schmitt
@ 2015-06-22 13:52 ` Ivan Gotovchits
  2015-06-22 13:53 ` Daniil Baturin
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 29+ messages in thread
From: Ivan Gotovchits @ 2015-06-22 13:52 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: OCaml Mailing List

[-- Attachment #1: Type: text/plain, Size: 1363 bytes --]

To my experience, this is a bad practice, that produces lots of confusion
to students.
They should clearly understand difference between writing code in a
toplevel and normal programming. A difference between
definition on a module level, and an expression. I usually say that `;;` is
not a part of a language, but just a part of a toplevel
command syntax (as well as toplevel directives), and strictly require not
to put `;;` in code.

On Mon, Jun 22, 2015 at 9:31 AM, Alan Schmitt <
alan.schmitt@polytechnique.org> wrote:

> Hello,
>
> In my Ocaml class, I tend to promote the use of ";;" to separate phrases
> (I'm basically following
>
> http://ocaml.org/learn/tutorials/structure_of_ocaml_programs.html#Usingandomittingand
> although I was not aware of this page when I created the course). My
> motivation is to minimize the difference between using the top-level and
> writing files.
>
> I am now wondering if this is a good practice. In a nutshell, would you
> rather use
>
> #+begin_src ocaml
> let x = 12;;
> print_endline "Hello World!"
> #+end_src
>
> or
>
> #+begin_src ocaml
> let x = 12
> let () = print_endline "Hello World!"
> #+end_src
>
> when teaching Ocaml?
>
> Thanks,
>
> Alan
>
> --
> OpenPGP Key ID : 040D0A3B4ED2E5C7
> Weekly CO₂ average (2015-05-30, Mauna Loa Observatory): 403.41 ppm
>

[-- Attachment #2: Type: text/html, Size: 1982 bytes --]

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

* Re: [Caml-list] use of ";;" when teaching Ocaml
  2015-06-22 13:31 [Caml-list] use of ";;" when teaching Ocaml Alan Schmitt
  2015-06-22 13:52 ` Ivan Gotovchits
@ 2015-06-22 13:53 ` Daniil Baturin
  2015-06-22 14:19 ` Gerd Stolpmann
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 29+ messages in thread
From: Daniil Baturin @ 2015-06-22 13:53 UTC (permalink / raw)
  To: caml-list


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Alan,

Since it's never necessary in the source code, I think it's a bad
practice to use it. Also, since it's uncommon in real-life code, I think
it will only cause more confusion in a long run.

Besides, top level pattern matching adds more safety and expressivity. From

let () = some_func x y z

it's clear that some_func is called solely for its side effects, and the
compiler will throw a type error if expression "some_func x y z" doesn't
have type unit.

Also, I rarely type the ;; after every phrase in the REPL, I like the
ability to type or paste longer chunks of code and process them at once.

On 06/22/2015 07:31 PM, Alan Schmitt wrote:
> Hello,
>
> In my Ocaml class, I tend to promote the use of ";;" to separate phrases
> (I'm basically following
>
http://ocaml.org/learn/tutorials/structure_of_ocaml_programs.html#Usingandomittingand
> although I was not aware of this page when I created the course). My
> motivation is to minimize the difference between using the top-level and
> writing files.
>
> I am now wondering if this is a good practice. In a nutshell, would you
> rather use
>
> #+begin_src ocaml
> let x = 12;;
> print_endline "Hello World!"
> #+end_src
>
> or
>
> #+begin_src ocaml
> let x = 12
> let () = print_endline "Hello World!"
> #+end_src
>
> when teaching Ocaml?
>
> Thanks,
>
> Alan
>


- -- 
#!/usr/bin/env perl
@a=split(//, "daniil @ baturin  .  org" );# Daniil Baturin
@b=split(//,q/Px%!+o0Q6lh*7dp$.@8#%|y{/);while($i<24){$_.=
chr((ord(@b[$i])-ord(@a[$i])+62)%94+32);$i++};print"$_\n"#
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBAgAGBQJViBNTAAoJEEcm35UR4K8fx7EP/0hdXT0zt2qg4xUmGq3ibQwi
BMxh8ZKNBcKADAX7WuZxc/Os2FgemA51tl+hP2Jug+msx70rPjUKCLr02qR4iVPO
NVJWZLWKM69NevHasBvaXGWuo2nTaV3N8Sk7KNi1Lt68IlKPbA3oOLYGHFGWs/Sz
4lCdPAx5ySV27mBFWi3bBJzkjZUwZVV5OAazHilTf08YBJAAnfHl3cq82ha/YxyD
hwK5ObB2MDkMZ3OTwyQVbPloAtS9nQvmg3bKAcV8mFGmggUifaNLYXCjewKP0NZd
bR/2UpBc8fRc7NNGLzC4CTFEJQQlBVActgIdY+UKbkKJdVQ26nBnxluxOgsFvXu/
ilwbvgCWCzi/I0XLyfFE3e0eHM4RMB+Oci+y44JrNJ/dYwAPxPVhkXwKRx6QuoFF
OEtjxexWaRCJv1A0TvCfMTZS9G5zrfxtYFKwy+erhnUvZ8ozBZe2akrfYfch1oY6
0uFBE2FXO33WdySyu3W4xpfBhk6760LzioZdVTlOikwgKArsUCTCmTlQ0OOsSa8/
2tehYTq+Lw6bwdEaUt/7VabOGPcAy7u2JNuT402Ol9xy64PdnVMCkmux45xGIznm
twj5ZNEWldHna0x8us0H4cOIDLu33Ubu3Eq/1PFgx8gvcYa4CCIe4AyDm9vzXBP9
WeiWtzuTVh48l0+oe0rK
=KU/e
-----END PGP SIGNATURE-----



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

* Re: [Caml-list] use of ";;" when teaching Ocaml
  2015-06-22 13:31 [Caml-list] use of ";;" when teaching Ocaml Alan Schmitt
  2015-06-22 13:52 ` Ivan Gotovchits
  2015-06-22 13:53 ` Daniil Baturin
@ 2015-06-22 14:19 ` Gerd Stolpmann
  2015-06-22 15:48   ` Damien Doligez
  2015-06-22 16:42   ` Thomas Refis
  2015-06-22 17:04 ` Daniel Bünzli
  2015-06-22 23:41 ` Philippe Wang
  4 siblings, 2 replies; 29+ messages in thread
From: Gerd Stolpmann @ 2015-06-22 14:19 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: OCaml Mailing List

[-- Attachment #1: Type: text/plain, Size: 1785 bytes --]

Am Montag, den 22.06.2015, 15:31 +0200 schrieb Alan Schmitt:
> Hello,
> 
> In my Ocaml class, I tend to promote the use of ";;" to separate phrases
> (I'm basically following
> http://ocaml.org/learn/tutorials/structure_of_ocaml_programs.html#Usingandomittingand
> although I was not aware of this page when I created the course). My
> motivation is to minimize the difference between using the top-level and
> writing files.
> 
> I am now wondering if this is a good practice. In a nutshell, would you
> rather use
> 
> #+begin_src ocaml
> let x = 12;;
> print_endline "Hello World!"
> #+end_src
> 
> or
> 
> #+begin_src ocaml
> let x = 12
> let () = print_endline "Hello World!"
> #+end_src
> 
> when teaching Ocaml?

There is one downside of not using ";;", namely that you sometimes get
syntax errors much later than necessary. E.g. in

let x = 
  do_this();
  do_that();
let y = 6
let z =
  do_third_thing()

you get the syntax error at the position of the third "let" although it
is the extra semicolon at the end of the first definition. This can be
very confusing, and it is a very good reason to use ";;" outside the
toplevel. IMHO it is better to be honest about this issue. Because "let"
is an open-ended construction the ";;" can be useful as end marker, and
the compiler emits better error messages with more precise locations.

Gerd



> Thanks,
> 
> Alan
> 

-- 
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany    gerd@gerd-stolpmann.de
My OCaml site:          http://www.camlcity.org
Contact details:        http://www.camlcity.org/contact.html
Company homepage:       http://www.gerd-stolpmann.de
------------------------------------------------------------


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

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

* Re: [Caml-list] use of ";;" when teaching Ocaml
  2015-06-22 14:19 ` Gerd Stolpmann
@ 2015-06-22 15:48   ` Damien Doligez
  2015-06-22 15:56     ` Thomas Refis
  2015-06-22 16:07     ` Pippijn van Steenhoven
  2015-06-22 16:42   ` Thomas Refis
  1 sibling, 2 replies; 29+ messages in thread
From: Damien Doligez @ 2015-06-22 15:48 UTC (permalink / raw)
  To: Gerd Stolpmann; +Cc: Alan Schmitt, OCaml Mailing List

Gerd has totally nailed it, and that's the reason why I always use ;;
in my code.
If we had another keyword for toplevel let (let without in) the
situation would be quite different.

-- Damien


On Mon, Jun 22, 2015 at 10:19 AM, Gerd Stolpmann <info@gerd-stolpmann.de> wrote:
> Am Montag, den 22.06.2015, 15:31 +0200 schrieb Alan Schmitt:
>> Hello,
>>
>> In my Ocaml class, I tend to promote the use of ";;" to separate phrases
>> (I'm basically following
>> http://ocaml.org/learn/tutorials/structure_of_ocaml_programs.html#Usingandomittingand
>> although I was not aware of this page when I created the course). My
>> motivation is to minimize the difference between using the top-level and
>> writing files.
>>
>> I am now wondering if this is a good practice. In a nutshell, would you
>> rather use
>>
>> #+begin_src ocaml
>> let x = 12;;
>> print_endline "Hello World!"
>> #+end_src
>>
>> or
>>
>> #+begin_src ocaml
>> let x = 12
>> let () = print_endline "Hello World!"
>> #+end_src
>>
>> when teaching Ocaml?
>
> There is one downside of not using ";;", namely that you sometimes get
> syntax errors much later than necessary. E.g. in
>
> let x =
>   do_this();
>   do_that();
> let y = 6
> let z =
>   do_third_thing()
>
> you get the syntax error at the position of the third "let" although it
> is the extra semicolon at the end of the first definition. This can be
> very confusing, and it is a very good reason to use ";;" outside the
> toplevel. IMHO it is better to be honest about this issue. Because "let"
> is an open-ended construction the ";;" can be useful as end marker, and
> the compiler emits better error messages with more precise locations.
>
> Gerd
>
>
>
>> Thanks,
>>
>> Alan
>>
>
> --
> ------------------------------------------------------------
> Gerd Stolpmann, Darmstadt, Germany    gerd@gerd-stolpmann.de
> My OCaml site:          http://www.camlcity.org
> Contact details:        http://www.camlcity.org/contact.html
> Company homepage:       http://www.gerd-stolpmann.de
> ------------------------------------------------------------
>

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

* Re: [Caml-list] use of ";;" when teaching Ocaml
  2015-06-22 15:48   ` Damien Doligez
@ 2015-06-22 15:56     ` Thomas Refis
  2015-06-22 16:07       ` Mark Shinwell
  2015-06-22 16:07     ` Pippijn van Steenhoven
  1 sibling, 1 reply; 29+ messages in thread
From: Thomas Refis @ 2015-06-22 15:56 UTC (permalink / raw)
  To: Damien Doligez; +Cc: Gerd Stolpmann, Alan Schmitt, OCaml Mailing List

2015-06-22 16:48 GMT+01:00 Damien Doligez <damien.doligez@inria.fr>:
> Gerd has totally nailed it, and that's the reason why I always use ;;
> in my code.
> If we had another keyword for toplevel let (let without in) the
> situation would be quite different.

http://caml.inria.fr/pub/docs/manual-camlp4/manual007.html !

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

* Re: [Caml-list] use of ";;" when teaching Ocaml
  2015-06-22 15:56     ` Thomas Refis
@ 2015-06-22 16:07       ` Mark Shinwell
  2015-06-22 16:30         ` Gerd Stolpmann
  2015-06-22 17:42         ` Francois Berenger
  0 siblings, 2 replies; 29+ messages in thread
From: Mark Shinwell @ 2015-06-22 16:07 UTC (permalink / raw)
  To: Thomas Refis
  Cc: Damien Doligez, Gerd Stolpmann, Alan Schmitt, OCaml Mailing List

I've heard the argument of Gerd from various people on many occasions.
Personally, I don't buy it; I think the situation where the error
message is deficient doesn't happen very often, whereas ";;" is
syntactic clutter that I have to see every day (and would rather not
see).

Mark

On 22 June 2015 at 16:56, Thomas Refis <thomas.refis@gmail.com> wrote:
> 2015-06-22 16:48 GMT+01:00 Damien Doligez <damien.doligez@inria.fr>:
>> Gerd has totally nailed it, and that's the reason why I always use ;;
>> in my code.
>> If we had another keyword for toplevel let (let without in) the
>> situation would be quite different.
>
> http://caml.inria.fr/pub/docs/manual-camlp4/manual007.html !
>
> --
> 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

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

* Re: [Caml-list] use of ";;" when teaching Ocaml
  2015-06-22 15:48   ` Damien Doligez
  2015-06-22 15:56     ` Thomas Refis
@ 2015-06-22 16:07     ` Pippijn van Steenhoven
  2015-06-22 16:25       ` Daniel Bünzli
  2015-06-22 18:18       ` Steve Zdancewic
  1 sibling, 2 replies; 29+ messages in thread
From: Pippijn van Steenhoven @ 2015-06-22 16:07 UTC (permalink / raw)
  To: Damien Doligez; +Cc: Gerd Stolpmann, Alan Schmitt, OCaml Mailing List

[-- Attachment #1: Type: text/plain, Size: 632 bytes --]

On Mon, Jun 22, 2015 at 11:48:21AM -0400, Damien Doligez wrote:
> Gerd has totally nailed it, and that's the reason why I always use ;;
> in my code.
> If we had another keyword for toplevel let (let without in) the
> situation would be quite different.

I have a rule (which I introduced recently, and thus don't yet follow
much in my code) to use ;; to terminate all unit-returning (therefore
effectful) functions. Pure functions or effectful functions with a proper
return value never have the trailing-semicolon issue. An alternative
solution is to always return () from unit-returning functions, but I
found ;; more appealing.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

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

* Re: [Caml-list] use of ";;" when teaching Ocaml
  2015-06-22 16:07     ` Pippijn van Steenhoven
@ 2015-06-22 16:25       ` Daniel Bünzli
  2015-06-22 18:18       ` Steve Zdancewic
  1 sibling, 0 replies; 29+ messages in thread
From: Daniel Bünzli @ 2015-06-22 16:25 UTC (permalink / raw)
  To: Pippijn van Steenhoven
  Cc: Damien Doligez, Gerd Stolpmann, Alan Schmitt, OCaml Mailing List

Le lundi, 22 juin 2015 à 17:07, Pippijn van Steenhoven a écrit :
> An alternative solution is to always return () from unit-returning functions, but I
> found ;; more appealing.

Why "more appealing", it is much less clear. Other people will also use ;; for functions that do return values other than unit so I can't possibly read code with your convention in mind.  

unit is () so return () that makes things very clear (that's what I personally do).

Best,

Daniel  



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

* Re: [Caml-list] use of ";;" when teaching Ocaml
  2015-06-22 16:07       ` Mark Shinwell
@ 2015-06-22 16:30         ` Gerd Stolpmann
  2015-06-22 16:47           ` Mark Shinwell
  2015-06-22 17:18           ` Török Edwin
  2015-06-22 17:42         ` Francois Berenger
  1 sibling, 2 replies; 29+ messages in thread
From: Gerd Stolpmann @ 2015-06-22 16:30 UTC (permalink / raw)
  To: Mark Shinwell
  Cc: Thomas Refis, Damien Doligez, Alan Schmitt, OCaml Mailing List

[-- Attachment #1: Type: text/plain, Size: 2375 bytes --]

Am Montag, den 22.06.2015, 17:07 +0100 schrieb Mark Shinwell:
> I've heard the argument of Gerd from various people on many occasions.
> Personally, I don't buy it; I think the situation where the error
> message is deficient doesn't happen very often, whereas ";;" is
> syntactic clutter that I have to see every day (and would rather not
> see).

Note that I personally normally don't use ;; because I am very aware of
the problem and fluent enough in the OCaml syntax to help myself. I was
mentioning this point because beginners are not fluent, and they will
run into the problem of getting syntax errors where everything looks
alright.

Also, I actually don't see why not using ";;" is considered cleaner.
It's a bit like writing sentences without full stop (and I think the
analogy to natural languages is quite insightful because there you also
have the situation of open-ended syntactical constructions, and nobody
complains when authors use "." to mark the end of sentences). After all,
it's a matter of preference and practical usefulness.

As a side note, the situation would be different if the compiler emitted
warnings about obviously wrong indentation, because the information
where the writer thinks that a new definition begins is also already
included in the indentation.

Gerd

> 
> Mark
> 
> On 22 June 2015 at 16:56, Thomas Refis <thomas.refis@gmail.com> wrote:
> > 2015-06-22 16:48 GMT+01:00 Damien Doligez <damien.doligez@inria.fr>:
> >> Gerd has totally nailed it, and that's the reason why I always use ;;
> >> in my code.
> >> If we had another keyword for toplevel let (let without in) the
> >> situation would be quite different.
> >
> > http://caml.inria.fr/pub/docs/manual-camlp4/manual007.html !
> >
> > --
> > 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

-- 
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany    gerd@gerd-stolpmann.de
My OCaml site:          http://www.camlcity.org
Contact details:        http://www.camlcity.org/contact.html
Company homepage:       http://www.gerd-stolpmann.de
------------------------------------------------------------


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

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

* Re: [Caml-list] use of ";;" when teaching Ocaml
  2015-06-22 14:19 ` Gerd Stolpmann
  2015-06-22 15:48   ` Damien Doligez
@ 2015-06-22 16:42   ` Thomas Refis
  2015-06-22 16:47     ` David House
  2015-06-22 17:08     ` Daniil Baturin
  1 sibling, 2 replies; 29+ messages in thread
From: Thomas Refis @ 2015-06-22 16:42 UTC (permalink / raw)
  To: Gerd Stolpmann; +Cc: Alan Schmitt, OCaml Mailing List

2015-06-22 15:19 GMT+01:00 Gerd Stolpmann <info@gerd-stolpmann.de>:
> There is one downside of not using ";;", namely that you sometimes get
> syntax errors much later than necessary. E.g. in
>
> let x =
>   do_this();
>   do_that();
> let y = 6
> let z =
>   do_third_thing()
>
> you get the syntax error at the position of the third "let" although it
> is the extra semicolon at the end of the first definition. This can be
> very confusing, and it is a very good reason to use ";;" outside the
> toplevel. IMHO it is better to be honest about this issue. Because "let"
> is an open-ended construction the ";;" can be useful as end marker, and
> the compiler emits better error messages with more precise locations.

The argument seems a bit weak.
The example is (if I understand correctly): "I have a trailing
semicolon which the compiler doesn't report properly but instead tells
me there is a syntax error in a completely unrelated place! If you
place double semicolons in your code, that doesn't happen!".
But it could also be understood as: "I usually place double
semicolons, but in this case I forgot. And the compiler doesn't report
this properly but instead tells me there is a syntax error in a
completely unrelated place!".

You face the same problem either way, you still have to be "fluent" to
know where to look when you encounter this error.
And I'd guess a beginner is as likely to forget the ";;" as to leave a
trailing ";".

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

* Re: [Caml-list] use of ";;" when teaching Ocaml
  2015-06-22 16:42   ` Thomas Refis
@ 2015-06-22 16:47     ` David House
  2015-06-22 17:08     ` Daniil Baturin
  1 sibling, 0 replies; 29+ messages in thread
From: David House @ 2015-06-22 16:47 UTC (permalink / raw)
  To: Thomas Refis; +Cc: Gerd Stolpmann, Alan Schmitt, OCaml Mailing List

[-- Attachment #1: Type: text/plain, Size: 2163 bytes --]

That's true, although it's probably a little easier to spot a missing ;;
than a non-missing trailing ;.

I expect that on balance you'll have better errors more often with using
;;. So it seems sensible to use it for teaching beginners. Once you're an
old hand like Mark Shinwell, you can make up your mind whether it's worth
keeping it up or not ;)

On 22 June 2015 at 17:42, Thomas Refis <thomas.refis@gmail.com> wrote:

> 2015-06-22 15:19 GMT+01:00 Gerd Stolpmann <info@gerd-stolpmann.de>:
> > There is one downside of not using ";;", namely that you sometimes get
> > syntax errors much later than necessary. E.g. in
> >
> > let x =
> >   do_this();
> >   do_that();
> > let y = 6
> > let z =
> >   do_third_thing()
> >
> > you get the syntax error at the position of the third "let" although it
> > is the extra semicolon at the end of the first definition. This can be
> > very confusing, and it is a very good reason to use ";;" outside the
> > toplevel. IMHO it is better to be honest about this issue. Because "let"
> > is an open-ended construction the ";;" can be useful as end marker, and
> > the compiler emits better error messages with more precise locations.
>
> The argument seems a bit weak.
> The example is (if I understand correctly): "I have a trailing
> semicolon which the compiler doesn't report properly but instead tells
> me there is a syntax error in a completely unrelated place! If you
> place double semicolons in your code, that doesn't happen!".
> But it could also be understood as: "I usually place double
> semicolons, but in this case I forgot. And the compiler doesn't report
> this properly but instead tells me there is a syntax error in a
> completely unrelated place!".
>
> You face the same problem either way, you still have to be "fluent" to
> know where to look when you encounter this error.
> And I'd guess a beginner is as likely to forget the ";;" as to leave a
> trailing ";".
>
> --
> 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
>

[-- Attachment #2: Type: text/html, Size: 3179 bytes --]

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

* Re: [Caml-list] use of ";;" when teaching Ocaml
  2015-06-22 16:30         ` Gerd Stolpmann
@ 2015-06-22 16:47           ` Mark Shinwell
  2015-06-22 17:08             ` Daniel Bünzli
  2015-06-22 18:56             ` Gerd Stolpmann
  2015-06-22 17:18           ` Török Edwin
  1 sibling, 2 replies; 29+ messages in thread
From: Mark Shinwell @ 2015-06-22 16:47 UTC (permalink / raw)
  To: Gerd Stolpmann
  Cc: Thomas Refis, Damien Doligez, Alan Schmitt, OCaml Mailing List

On 22 June 2015 at 17:30, Gerd Stolpmann <info@gerd-stolpmann.de> wrote:
> Also, I actually don't see why not using ";;" is considered cleaner.
> It's a bit like writing sentences without full stop

There is a "full stop", though: it's a blank line.
In my book, the code of functions shouldn't contain blank lines (I've
found this to often be a good sign that the function is too long
and/or complicated).

Mark

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

* Re: [Caml-list] use of ";;" when teaching Ocaml
  2015-06-22 13:31 [Caml-list] use of ";;" when teaching Ocaml Alan Schmitt
                   ` (2 preceding siblings ...)
  2015-06-22 14:19 ` Gerd Stolpmann
@ 2015-06-22 17:04 ` Daniel Bünzli
  2015-06-22 23:41 ` Philippe Wang
  4 siblings, 0 replies; 29+ messages in thread
From: Daniel Bünzli @ 2015-06-22 17:04 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: OCaml Mailing List

Le lundi, 22 juin 2015 à 14:31, Alan Schmitt a écrit :
> I am now wondering if this is a good practice. In a nutshell, would you
> rather use
>  
> #+begin_src ocaml
> let x = 12;;
> print_endline "Hello World!"
> #+end_src
>  
> or
>  
> #+begin_src ocaml
> let x = 12
> let () = print_endline "Hello World!"
> #+end_src
>  
> when teaching Ocaml?
  
Leaving the ;; polemic aside (which you can also write in the second form if you want to), I would definitively teach the second form as OCaml's default set of warnings don't warn you about potential partial applications on the lines of the first form. This can lead to puzzling "nothing happens" bugs, especially for a new commer.

For example:  

output_string stdout;;

compiles without a hitch — that's also why it should be, as you rightly propose, `let () = …` and not `let _ = …`

Best,

Daniel



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

* Re: [Caml-list] use of ";;" when teaching Ocaml
  2015-06-22 16:47           ` Mark Shinwell
@ 2015-06-22 17:08             ` Daniel Bünzli
  2015-06-22 18:56             ` Gerd Stolpmann
  1 sibling, 0 replies; 29+ messages in thread
From: Daniel Bünzli @ 2015-06-22 17:08 UTC (permalink / raw)
  To: Mark Shinwell
  Cc: Gerd Stolpmann, Thomas Refis, Damien Doligez, Alan Schmitt,
	OCaml Mailing List

Le lundi, 22 juin 2015 à 17:47, Mark Shinwell a écrit :
> In my book, the code of functions shouldn't contain blank lines (I've
> found this to often be a good sign that the function is too long
> and/or complicated).

I agree very much. I became so much accustomed of not having blank lines in the code of my functions that I find other people's code very hard to follow when they do so (especially tracking the different scopes and/or determining where the functions ends).

Daniel

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

* Re: [Caml-list] use of ";;" when teaching Ocaml
  2015-06-22 16:42   ` Thomas Refis
  2015-06-22 16:47     ` David House
@ 2015-06-22 17:08     ` Daniil Baturin
  1 sibling, 0 replies; 29+ messages in thread
From: Daniil Baturin @ 2015-06-22 17:08 UTC (permalink / raw)
  To: caml-list


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

>I have a trailing semicolon which the compiler doesn't report properly

It's probably a good idea to encourage beginners to always wrap
sequences in begin ... end

- -- 
#!/usr/bin/env perl
@a=split(//, "daniil @ baturin  .  org" );# Daniil Baturin
@b=split(//,q/Px%!+o0Q6lh*7dp$.@8#%|y{/);while($i<24){$_.=
chr((ord(@b[$i])-ord(@a[$i])+62)%94+32);$i++};print"$_\n"#
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBAgAGBQJViEEkAAoJEEcm35UR4K8fLwAQALVicPv3GMtvXNZvB02yg/An
ILSV2YvF4LzxOzh9WDL7oEGLMI7Rux5GVywE7dN8ClyMpjUCss1liZSBe6elRdKs
xUAP9L1oYdauyGHnNEcUom5j8SE/c4N4Tx+ELMzJwufiv5JiVLeplbQ0kW1fiWu8
FGSdtvslSlQzS4qv28RPPjXED3NQig9X/X++2asxIGPNYCM19R/LI9Mu/EEykRri
aqWoK8fbXJCbMrjP7eQ2+ztLYsYXAjOoDDnnVehTfR8Ql3GxgnohmUXfdB7fA7k6
PTCawFLFXAA+HrPlse+w0WOmQhxEBq1Rc1O2Ac8PITcrMHCVe8OyVtLcX9+Uyaye
N0+kwEDHaMeMgbYDNG6Tlr88HC8Nd6dfPL/br0gn8LUmY/W0mUTTLwkPnRwXLSsY
4ZGTTnL+lfc2ADFQMBtftUfyXwzHLeHLGcUtFBvL1ZDYXFCfLNHSalRnCQSLwFWC
U078sXHF43BUx8Rzum6uZLxcmEUCRT93BQ6PfkxZk+GnIePMdGPEUn0B5vUphDSD
d5ca+dj0ZqVgyCuMUS2KHmYd02lW7fPYQ51gs7hoFL4+Oj9LsbwAzThkOgXyfIfe
m8aK3aZ8gw8TLoXYWev41khxRJ74ECnx9QWWyqorUhtAe5a6MjFSpXI+TWK9UDva
5G80jHau2qIGsDFni/SP
=OQrT
-----END PGP SIGNATURE-----


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

* Re: [Caml-list] use of ";;" when teaching Ocaml
  2015-06-22 16:30         ` Gerd Stolpmann
  2015-06-22 16:47           ` Mark Shinwell
@ 2015-06-22 17:18           ` Török Edwin
  1 sibling, 0 replies; 29+ messages in thread
From: Török Edwin @ 2015-06-22 17:18 UTC (permalink / raw)
  To: caml-list

On 06/22/2015 07:30 PM, Gerd Stolpmann wrote:
> Am Montag, den 22.06.2015, 17:07 +0100 schrieb Mark Shinwell:
>> I've heard the argument of Gerd from various people on many occasions.
>> Personally, I don't buy it; I think the situation where the error
>> message is deficient doesn't happen very often, whereas ";;" is
>> syntactic clutter that I have to see every day (and would rather not
>> see).
> 
> Note that I personally normally don't use ;; because I am very aware of
> the problem and fluent enough in the OCaml syntax to help myself. I was
> mentioning this point because beginners are not fluent, and they will
> run into the problem of getting syntax errors where everything looks
> alright.
> [...]
> As a side note, the situation would be different if the compiler emitted
> warnings about obviously wrong indentation, because the information
> where the writer thinks that a new definition begins is also already
> included in the indentation.

Although ;; was useful to me while learning OCaml, as a debugging tool for syntax errors [1],
nowadays editor support is much better (ocp-indent, ocamlmerlin) and you usually see the misplaced ; immediately
(or after reindenting the code if you made modifications).

[1] tried the revised syntax route too for a while, but since most material and examples on OCaml are about the original syntax
it was better to learn just that instead of constantly switching between the two

Best regards,
--Edwin



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

* Re: [Caml-list] use of ";;" when teaching Ocaml
  2015-06-22 16:07       ` Mark Shinwell
  2015-06-22 16:30         ` Gerd Stolpmann
@ 2015-06-22 17:42         ` Francois Berenger
  2015-06-22 17:46           ` Ivan Gotovchits
  2015-06-22 17:53           ` John Whitington
  1 sibling, 2 replies; 29+ messages in thread
From: Francois Berenger @ 2015-06-22 17:42 UTC (permalink / raw)
  To: caml-list

On 06/22/2015 06:07 PM, Mark Shinwell wrote:
> I've heard the argument of Gerd from various people on many occasions.
> Personally, I don't buy it; I think the situation where the error
> message is deficient doesn't happen very often, whereas ";;" is
> syntactic clutter that I have to see every day (and would rather not
> see).
>
> Mark

I am curious.
How do you make this file compile without ';;' in it ?

# cat src/test.ml
---
let main () =
   failwith "not implemented yet"
;;

main ()
---

I always use ';;' just for that use case.
I really don't know if there is another way that fits a single file.

> On 22 June 2015 at 16:56, Thomas Refis <thomas.refis@gmail.com> wrote:
>> 2015-06-22 16:48 GMT+01:00 Damien Doligez <damien.doligez@inria.fr>:
>>> Gerd has totally nailed it, and that's the reason why I always use ;;
>>> in my code.
>>> If we had another keyword for toplevel let (let without in) the
>>> situation would be quite different.
>>
>> http://caml.inria.fr/pub/docs/manual-camlp4/manual007.html !
>>
>> --
>> 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
>

-- 
Regards,
Francois.
"When in doubt, use more types"

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

* Re: [Caml-list] use of ";;" when teaching Ocaml
  2015-06-22 17:42         ` Francois Berenger
@ 2015-06-22 17:46           ` Ivan Gotovchits
  2015-06-22 17:53           ` John Whitington
  1 sibling, 0 replies; 29+ messages in thread
From: Ivan Gotovchits @ 2015-06-22 17:46 UTC (permalink / raw)
  To: Francois Berenger; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 919 bytes --]

On Mon, Jun 22, 2015 at 1:42 PM, Francois Berenger <
francois.berenger@inria.fr> wrote:

> On 06/22/2015 06:07 PM, Mark Shinwell wrote:
>
>> I've heard the argument of Gerd from various people on many occasions.
>> Personally, I don't buy it; I think the situation where the error
>> message is deficient doesn't happen very often, whereas ";;" is
>> syntactic clutter that I have to see every day (and would rather not
>> see).
>>
>> Mark
>>
>
> I am curious.
> How do you make this file compile without ';;' in it ?
>
> # cat src/test.ml
> ---
> let main () =
>   failwith "not implemented yet"
> ;;
>
> main ()
> ---
>
> I always use ';;' just for that use case.
> I really don't know if there is another way that fits a single file.


An idiomatic way is to write:

    let () = main ()

Your example is particular case, showing why `;;` is bad. Because it forces
compiler to take
code that is not in ocaml syntax.

[-- Attachment #2: Type: text/html, Size: 1620 bytes --]

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

* Re: [Caml-list] use of ";;" when teaching Ocaml
  2015-06-22 17:42         ` Francois Berenger
  2015-06-22 17:46           ` Ivan Gotovchits
@ 2015-06-22 17:53           ` John Whitington
  1 sibling, 0 replies; 29+ messages in thread
From: John Whitington @ 2015-06-22 17:53 UTC (permalink / raw)
  To: Francois Berenger; +Cc: caml-list

Hi Francois,

cat src/test.ml
---
failwith "I don't recommend this"
---

(Assuming you're not exporting main in an interface, and just want an 
error if the module is linked and its initialiser run.)

John

Francois Berenger wrote:
> On 06/22/2015 06:07 PM, Mark Shinwell wrote:
>> I've heard the argument of Gerd from various people on many occasions.
>> Personally, I don't buy it; I think the situation where the error
>> message is deficient doesn't happen very often, whereas ";;" is
>> syntactic clutter that I have to see every day (and would rather not
>> see).
>>
>> Mark
>
> I am curious.
> How do you make this file compile without ';;' in it ?
>
> # cat src/test.ml
> ---
> let main () =
> failwith "not implemented yet"
> ;;
>
> main ()
> ---
>
> I always use ';;' just for that use case.
> I really don't know if there is another way that fits a single file.
>
>> On 22 June 2015 at 16:56, Thomas Refis <thomas.refis@gmail.com> wrote:
>>> 2015-06-22 16:48 GMT+01:00 Damien Doligez <damien.doligez@inria.fr>:
>>>> Gerd has totally nailed it, and that's the reason why I always use ;;
>>>> in my code.
>>>> If we had another keyword for toplevel let (let without in) the
>>>> situation would be quite different.
>>>
>>> http://caml.inria.fr/pub/docs/manual-camlp4/manual007.html !
>>>
>>> --
>>> 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
>>
>

-- 
John Whitington
Director, Coherent Graphics Ltd
http://www.coherentpdf.com/


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

* Re: [Caml-list] use of ";;" when teaching Ocaml
  2015-06-22 16:07     ` Pippijn van Steenhoven
  2015-06-22 16:25       ` Daniel Bünzli
@ 2015-06-22 18:18       ` Steve Zdancewic
  1 sibling, 0 replies; 29+ messages in thread
From: Steve Zdancewic @ 2015-06-22 18:18 UTC (permalink / raw)
  To: caml-list

At Penn we use a slightly different idiom: at the top level all 
"commands" should be _prefixed_ by ;;.  We don't think of ;; as 
terminating a declaration, instead we think of it as preceding a 
stateful operation.  This has the nice property of marking effectful 
code syntactically in the program, and students don't seem to mind. Some 
examples would be:

;; open Foo

let f x =
   let y = x ^ x in
   y ^ y

;; print_string f "x"

let g x = ...
let test () = assert_eq (g 3) 7

;; run_test "testing g" test


let main () = ...

;; main ()

--Steve

Steve Zdancewic
Professor, Dept. of Computer and Information Science
University of Pennsylvania
http://www.cis.upenn.edu/~stevez


On 6/22/15 12:07 PM, Pippijn van Steenhoven wrote:
> On Mon, Jun 22, 2015 at 11:48:21AM -0400, Damien Doligez wrote:
>> Gerd has totally nailed it, and that's the reason why I always use ;;
>> in my code.
>> If we had another keyword for toplevel let (let without in) the
>> situation would be quite different.
> I have a rule (which I introduced recently, and thus don't yet follow
> much in my code) to use ;; to terminate all unit-returning (therefore
> effectful) functions. Pure functions or effectful functions with a proper
> return value never have the trailing-semicolon issue. An alternative
> solution is to always return () from unit-returning functions, but I
> found ;; more appealing.



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

* Re: [Caml-list] use of ";;" when teaching Ocaml
  2015-06-22 16:47           ` Mark Shinwell
  2015-06-22 17:08             ` Daniel Bünzli
@ 2015-06-22 18:56             ` Gerd Stolpmann
  1 sibling, 0 replies; 29+ messages in thread
From: Gerd Stolpmann @ 2015-06-22 18:56 UTC (permalink / raw)
  To: Mark Shinwell
  Cc: Thomas Refis, Damien Doligez, Alan Schmitt, OCaml Mailing List

[-- Attachment #1: Type: text/plain, Size: 1315 bytes --]

Am Montag, den 22.06.2015, 17:47 +0100 schrieb Mark Shinwell:
> On 22 June 2015 at 17:30, Gerd Stolpmann <info@gerd-stolpmann.de> wrote:
> > Also, I actually don't see why not using ";;" is considered cleaner.
> > It's a bit like writing sentences without full stop
> 
> There is a "full stop", though: it's a blank line.
> In my book, the code of functions shouldn't contain blank lines (I've
> found this to often be a good sign that the function is too long
> and/or complicated).

This is irrelevant when the compiler doesn't understand blank lines.

Btw, there are various conventions in use. Personally, I prefer a clear
optical separation of functions, and typically use 2-3 blank lines,
allowing me the freedom of putting single blank lines here and there
into the function body for purely aesthetic reasons. But, as mentioned,
this is off topic, as our common friend, the OCaml compiler, cannot make
anything out of it.


Gerd
-- 
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany    gerd@gerd-stolpmann.de
My OCaml site:          http://www.camlcity.org
Contact details:        http://www.camlcity.org/contact.html
Company homepage:       http://www.gerd-stolpmann.de
------------------------------------------------------------


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

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

* Re: [Caml-list] use of ";;" when teaching Ocaml
  2015-06-22 13:31 [Caml-list] use of ";;" when teaching Ocaml Alan Schmitt
                   ` (3 preceding siblings ...)
  2015-06-22 17:04 ` Daniel Bünzli
@ 2015-06-22 23:41 ` Philippe Wang
  2015-06-23  1:15   ` Kenichi Asai
  2015-06-23 13:27   ` Alan Schmitt
  4 siblings, 2 replies; 29+ messages in thread
From: Philippe Wang @ 2015-06-22 23:41 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: OCaml Mailing List

In my opinion, it's a lot more relevant to use a very limited and very
simple subset of OCaml when teaching to beginners. And this subset
does not involve expressions at top-level because it's not worth the
trouble.

Writing `42;;` or `print_string "hello";;` does not help: in the best
case scenario, it won't be confusing, but for most people, it will be
one more thing to understand, and there are so many things that are
more interesting to understand.

Also, using the interactive top-level loop is, in my opinion, not good
for beginners. It should only be presented to those who already
understand very well the "core" of OCaml. The most frequent issue with
the top-level loop is that it gets in the way of the notion of
compiling a program, and it might give the false impression that OCaml
can be interpreted.

Well, if all your student are exceptionally intelligent, forget what
I'm saying. My experience, as someone who has taught OCaml to
L2/L3/M1/M2 students (at University Paris 6), is mostly based on
teaching to very various students, all sorts from extremely idiotic to
extremely smart, so I prefer to make every one's work as gainful as
possible, with as little superfluous concepts (including advanced
topics that don't look like advanced topics to people who are very
used to using OCaml) as I possibly can. On the other hand, if your
students are not exceptionally smart, I really believe you should act
as ;; simply didn't exist in OCaml (the smartest ones will discover ;;
by themselves, or you might want to show it just to them, and learn to
use it efficiently by themselves too).

Philippe Wang

On Mon, Jun 22, 2015 at 3:31 PM, Alan Schmitt
<alan.schmitt@polytechnique.org> wrote:
> Hello,
>
> In my Ocaml class, I tend to promote the use of ";;" to separate phrases
> (I'm basically following
> http://ocaml.org/learn/tutorials/structure_of_ocaml_programs.html#Usingandomittingand
> although I was not aware of this page when I created the course). My
> motivation is to minimize the difference between using the top-level and
> writing files.
>
> I am now wondering if this is a good practice. In a nutshell, would you
> rather use
>
> #+begin_src ocaml
> let x = 12;;
> print_endline "Hello World!"
> #+end_src
>
> or
>
> #+begin_src ocaml
> let x = 12
> let () = print_endline "Hello World!"
> #+end_src
>
> when teaching Ocaml?
>
> Thanks,
>
> Alan
>

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

* Re: [Caml-list] use of ";;" when teaching Ocaml
  2015-06-22 23:41 ` Philippe Wang
@ 2015-06-23  1:15   ` Kenichi Asai
  2015-06-23 13:27   ` Alan Schmitt
  1 sibling, 0 replies; 29+ messages in thread
From: Kenichi Asai @ 2015-06-23  1:15 UTC (permalink / raw)
  To: Philippe Wang; +Cc: Alan Schmitt, OCaml Mailing List

> In my opinion, it's a lot more relevant to use a very limited and very
> simple subset of OCaml when teaching to beginners. And this subset
> does not involve expressions at top-level

I totally agree.  Assuming that you are teaching functional
programming in general using OCaml, rather than teaching the OCaml
language itself, I believe a program should consist of only
definitions, not toplevel expressions.  I even think it would have
been nice if we had language levels for beginners as in Racket to
enforce it (with better error messages).

-- 
Kenichi Asai

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

* Re: [Caml-list] use of ";;" when teaching Ocaml
  2015-06-22 23:41 ` Philippe Wang
  2015-06-23  1:15   ` Kenichi Asai
@ 2015-06-23 13:27   ` Alan Schmitt
  2015-06-23 13:35     ` Ivan Gotovchits
  2015-06-25 16:51     ` Philippe Wang
  1 sibling, 2 replies; 29+ messages in thread
From: Alan Schmitt @ 2015-06-23 13:27 UTC (permalink / raw)
  To: Philippe Wang; +Cc: OCaml Mailing List

[-- Attachment #1: Type: text/plain, Size: 1546 bytes --]

Hello,

Thanks to everyone for your answers, this has given me much food for
thought.

On 2015-06-23 01:41, Philippe Wang <mail@philippewang.info> writes:

> In my opinion, it's a lot more relevant to use a very limited and very
> simple subset of OCaml when teaching to beginners. And this subset
> does not involve expressions at top-level because it's not worth the
> trouble.

I like this approach because it amounts to saying "one always starts
a phrase with 'let' or 'type'" (and later in the year there can be
'open', 'module', 'include'). I sure can live without top-level
expressions.

On the other hand, I also like the idea of terminating phrases, simply
because explaining when it terminates is not trivial otherwise, as
a 'let' may not be the beginning of a phrase.

> Also, using the interactive top-level loop is, in my opinion, not good
> for beginners. It should only be presented to those who already
> understand very well the "core" of OCaml. The most frequent issue with
> the top-level loop is that it gets in the way of the notion of
> compiling a program, and it might give the false impression that OCaml
> can be interpreted.

I am curious about this. My goal is to teach the language, and I find
that a REPL backed with a file works great to do this (using tuareg or
ocaml-top). What do you use to make sure students have a fast
compile/debug cycle?

Thanks again,

Alan

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7
Weekly CO₂ average (2015-05-30, Mauna Loa Observatory): 403.41 ppm

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

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

* Re: [Caml-list] use of ";;" when teaching Ocaml
  2015-06-23 13:27   ` Alan Schmitt
@ 2015-06-23 13:35     ` Ivan Gotovchits
  2015-06-23 13:36       ` Ivan Gotovchits
  2015-06-25 16:51     ` Philippe Wang
  1 sibling, 1 reply; 29+ messages in thread
From: Ivan Gotovchits @ 2015-06-23 13:35 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: Philippe Wang, OCaml Mailing List

[-- Attachment #1: Type: text/plain, Size: 1820 bytes --]

On Tue, Jun 23, 2015 at 9:27 AM, Alan Schmitt <
alan.schmitt@polytechnique.org> wrote:

> Hello,
>
> Thanks to everyone for your answers, this has given me much food for
> thought.
>
> On 2015-06-23 01:41, Philippe Wang <mail@philippewang.info> writes:
>
> > In my opinion, it's a lot more relevant to use a very limited and very
> > simple subset of OCaml when teaching to beginners. And this subset
> > does not involve expressions at top-level because it's not worth the
> > trouble.
>
> I like this approach because it amounts to saying "one always starts
> a phrase with 'let' or 'type'" (and later in the year there can be
> 'open', 'module', 'include'). I sure can live without top-level
> expressions.
>
> On the other hand, I also like the idea of terminating phrases, simply
> because explaining when it terminates is not trivial otherwise, as
> a 'let' may not be the beginning of a phrase.
>
> > Also, using the interactive top-level loop is, in my opinion, not good
> > for beginners. It should only be presented to those who already
> > understand very well the "core" of OCaml. The most frequent issue with
> > the top-level loop is that it gets in the way of the notion of
> > compiling a program, and it might give the false impression that OCaml
> > can be interpreted.
>
> I am curious about this. My goal is to teach the language, and I find
> that a REPL backed with a file works great to do this (using tuareg or
> ocaml-top). What do you use to make sure students have a fast
> compile/debug cycle?
>

You should take a look into ocaml-top [1]. It is a toplevel that doesn't
require `;;` at all.





>
> Thanks again,
>
> Alan
>
> --
> OpenPGP Key ID : 040D0A3B4ED2E5C7
> Weekly CO₂ average (2015-05-30, Mauna Loa Observatory): 403.41 ppm
>

[-- Attachment #2: Type: text/html, Size: 2647 bytes --]

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

* Re: [Caml-list] use of ";;" when teaching Ocaml
  2015-06-23 13:35     ` Ivan Gotovchits
@ 2015-06-23 13:36       ` Ivan Gotovchits
  0 siblings, 0 replies; 29+ messages in thread
From: Ivan Gotovchits @ 2015-06-23 13:36 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: Philippe Wang, OCaml Mailing List

[-- Attachment #1: Type: text/plain, Size: 2031 bytes --]

forget the link...

[1]: http://www.typerex.org/ocaml-top.html

On Tue, Jun 23, 2015 at 9:35 AM, Ivan Gotovchits <ivg@ieee.org> wrote:

>
>
> On Tue, Jun 23, 2015 at 9:27 AM, Alan Schmitt <
> alan.schmitt@polytechnique.org> wrote:
>
>> Hello,
>>
>> Thanks to everyone for your answers, this has given me much food for
>> thought.
>>
>> On 2015-06-23 01:41, Philippe Wang <mail@philippewang.info> writes:
>>
>> > In my opinion, it's a lot more relevant to use a very limited and very
>> > simple subset of OCaml when teaching to beginners. And this subset
>> > does not involve expressions at top-level because it's not worth the
>> > trouble.
>>
>> I like this approach because it amounts to saying "one always starts
>> a phrase with 'let' or 'type'" (and later in the year there can be
>> 'open', 'module', 'include'). I sure can live without top-level
>> expressions.
>>
>> On the other hand, I also like the idea of terminating phrases, simply
>> because explaining when it terminates is not trivial otherwise, as
>> a 'let' may not be the beginning of a phrase.
>>
>> > Also, using the interactive top-level loop is, in my opinion, not good
>> > for beginners. It should only be presented to those who already
>> > understand very well the "core" of OCaml. The most frequent issue with
>> > the top-level loop is that it gets in the way of the notion of
>> > compiling a program, and it might give the false impression that OCaml
>> > can be interpreted.
>>
>> I am curious about this. My goal is to teach the language, and I find
>> that a REPL backed with a file works great to do this (using tuareg or
>> ocaml-top). What do you use to make sure students have a fast
>> compile/debug cycle?
>>
>
> You should take a look into ocaml-top [1]. It is a toplevel that doesn't
> require `;;` at all.
>
>
>
>
>
>>
>> Thanks again,
>>
>> Alan
>>
>> --
>> OpenPGP Key ID : 040D0A3B4ED2E5C7
>> Weekly CO₂ average (2015-05-30, Mauna Loa Observatory): 403.41 ppm
>>
>
>

[-- Attachment #2: Type: text/html, Size: 3174 bytes --]

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

* Re: [Caml-list] use of ";;" when teaching Ocaml
  2015-06-23 13:27   ` Alan Schmitt
  2015-06-23 13:35     ` Ivan Gotovchits
@ 2015-06-25 16:51     ` Philippe Wang
  2015-06-29  0:12       ` Philippe Wang
  1 sibling, 1 reply; 29+ messages in thread
From: Philippe Wang @ 2015-06-25 16:51 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: OCaml Mailing List

On Tue, Jun 23, 2015 at 3:27 PM, Alan Schmitt
<alan.schmitt@polytechnique.org> wrote:
> Hello,
>
> Thanks to everyone for your answers, this has given me much food for
> thought.
>
> On 2015-06-23 01:41, Philippe Wang <mail@philippewang.info> writes:
>
>> In my opinion, it's a lot more relevant to use a very limited and very
>> simple subset of OCaml when teaching to beginners. And this subset
>> does not involve expressions at top-level because it's not worth the
>> trouble.
>
> I like this approach because it amounts to saying "one always starts
> a phrase with 'let' or 'type'" (and later in the year there can be
> 'open', 'module', 'include'). I sure can live without top-level
> expressions.
>
> On the other hand, I also like the idea of terminating phrases, simply
> because explaining when it terminates is not trivial otherwise, as
> a 'let' may not be the beginning of a phrase.

Well, a computer is (by definition) stupid, and languages made by
humans are like human: none is perfect! :)
So... there's the global `let` and the local `let...in`, it sucks a
little but everyone is free to propose a new language (yeah, that's
what i used to tell student who would complain about design)  :)


>> Also, using the interactive top-level loop is, in my opinion, not good
>> for beginners. It should only be presented to those who already
>> understand very well the "core" of OCaml. The most frequent issue with
>> the top-level loop is that it gets in the way of the notion of
>> compiling a program, and it might give the false impression that OCaml
>> can be interpreted.
>
> I am curious about this. My goal is to teach the language, and I find
> that a REPL backed with a file works great to do this (using tuareg or
> ocaml-top). What do you use to make sure students have a fast
> compile/debug cycle?

Well, it depends a lot on the skills of the students: for beginners, I
believe it doesn't help a lot to have the REPL. The one very annoying
thing that goes with REPLs is understanding the difference between the
result of a program and what is printed on stdout (or even stderr).
For instance, lots of students would mix "42;;" and "print_int 42;;"
and you would need to spend quite sometime explaining this and
repeating they are not the same at all, and spend quite some energy
containing the bomb that wants to detonate inside of you when they
keep repeating that mistake!

But, if you have some experimented programmers, or some extremely
smart beginners, you may have fun with this kind of things because
there actually are so many of them in OCaml, like a gigantic gold
mine. (I have to admit, I kind of like it. But when I want efficiency,
I don't go there.)

So, fast compile/debug cycle? Well, my suggestion is to use a Makefile
and invoke make as often as possible (meaning as soon ). If the
program is small enough, I won't even use make, I will directly call
ocamlc. (Not ocamlopt, because ocamlc is faster at compiling than
ocamlopt.) Well, then when the program becomes "big" enough, I will
use a Makefile.
The errors messages of ocamlc/ocamlopt are not worse than ocaml
REPL's, sometimes they are even better. Also, it will avoid the
awkward situation where your program works fine with ocaml but won't
compile with ocamlc/ocamlopt, because there's a weirdo that has weak
types... ;-)
Note that it's possible to use `ocaml program.ml`, so you don't have
to do something like `ocamlc program.ml && ./a.out`.

Also, it's not bad to tell your students to declare all their
functions before implementing them. Use for instance
let koala food = failwith "koala not implemented yet", especially when
they have mutually recursive functions: this way they may compile
their programs before they have (wrongly-)implemented everything, and
look for errors, instead of having to have a giant mess to deal
with...

Cheers,
Philippe Wang

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

* Re: [Caml-list] use of ";;" when teaching Ocaml
  2015-06-25 16:51     ` Philippe Wang
@ 2015-06-29  0:12       ` Philippe Wang
  0 siblings, 0 replies; 29+ messages in thread
From: Philippe Wang @ 2015-06-29  0:12 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: OCaml Mailing List

Apart from the ";;" thing, if you teach to beginners (well, actually
it could help experimented programmers as well), I suggest to make
function signatures explicit, meaning:
write
let f (x : int) : int = x + 1
instead of
let f x = x + 1
or
let rec map (f : 'a -> 'b) (l : 'a list) : 'b list = ...
instead of
let rec map f l = ...

for two main reasons:
1. it helps if there are bugs! Bugs are easier to find when we tell
the type checker what we expect.
2. it helps the students, because type inference is not that helpful.

But, I wouldn't force students to write those type annotations, except
perhaps the first few weeks...

Note that I would totally avoid this style:
let rec map : ('a -> 'b) -> 'a list -> 'b list = fun f l -> ...
(not that I don't like it, but I believe the other one is a lot more
efficient, pedagogically speaking)


Cheers,
Philippe Wang

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

end of thread, other threads:[~2015-06-29  0:12 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-22 13:31 [Caml-list] use of ";;" when teaching Ocaml Alan Schmitt
2015-06-22 13:52 ` Ivan Gotovchits
2015-06-22 13:53 ` Daniil Baturin
2015-06-22 14:19 ` Gerd Stolpmann
2015-06-22 15:48   ` Damien Doligez
2015-06-22 15:56     ` Thomas Refis
2015-06-22 16:07       ` Mark Shinwell
2015-06-22 16:30         ` Gerd Stolpmann
2015-06-22 16:47           ` Mark Shinwell
2015-06-22 17:08             ` Daniel Bünzli
2015-06-22 18:56             ` Gerd Stolpmann
2015-06-22 17:18           ` Török Edwin
2015-06-22 17:42         ` Francois Berenger
2015-06-22 17:46           ` Ivan Gotovchits
2015-06-22 17:53           ` John Whitington
2015-06-22 16:07     ` Pippijn van Steenhoven
2015-06-22 16:25       ` Daniel Bünzli
2015-06-22 18:18       ` Steve Zdancewic
2015-06-22 16:42   ` Thomas Refis
2015-06-22 16:47     ` David House
2015-06-22 17:08     ` Daniil Baturin
2015-06-22 17:04 ` Daniel Bünzli
2015-06-22 23:41 ` Philippe Wang
2015-06-23  1:15   ` Kenichi Asai
2015-06-23 13:27   ` Alan Schmitt
2015-06-23 13:35     ` Ivan Gotovchits
2015-06-23 13:36       ` Ivan Gotovchits
2015-06-25 16:51     ` Philippe Wang
2015-06-29  0:12       ` Philippe Wang

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