caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] let () =
@ 2004-08-03 14:46 Paul Argentoff
  2004-08-03 15:09 ` Yann Regis-Gianas
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Paul Argentoff @ 2004-08-03 14:46 UTC (permalink / raw)
  To: caml-list


Hello World!

Can anyone answer my silly question: what does "let () = bla" really mean?

-- 
Yours truly, WBR, Paul Argentoff.
Jabber:	paul@jabber.rtelekom.ru
RIPE:	PA1291-RIPE

-------------------
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/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] let () =
  2004-08-03 14:46 [Caml-list] let () = Paul Argentoff
@ 2004-08-03 15:09 ` Yann Regis-Gianas
  2004-08-03 15:10 ` Richard Jones
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Yann Regis-Gianas @ 2004-08-03 15:09 UTC (permalink / raw)
  To: caml-list

Le mardi 3 Août 2004 16:46, Paul Argentoff a écrit :
> Hello World!
>
> Can anyone answer my silly question: what does "let () = bla" really mean?

from http://caml.inria.fr/ocaml/htmlman/manual015.html#s:localdef :
let pattern1 =  expr1 and ... and  patternn =  exprn in  expr 

from http://caml.inria.fr/ocaml/htmlman/manual014.html :
pattern ::= value-name | ...

and given that '()' is the unique value of type unit, 'let () = bla' means "do 
a must-succeed-match between the expression bla and ()'. Thus, this also 
means "do nothing but evaluate (reduce) bla'.

Regards,

--
Y.

-------------------
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/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] let () =
  2004-08-03 14:46 [Caml-list] let () = Paul Argentoff
  2004-08-03 15:09 ` Yann Regis-Gianas
@ 2004-08-03 15:10 ` Richard Jones
  2004-08-03 15:11 ` John Prevost
  2004-08-03 17:08 ` Nicolas Cannasse
  3 siblings, 0 replies; 6+ messages in thread
From: Richard Jones @ 2004-08-03 15:10 UTC (permalink / raw)
  To: Paul Argentoff; +Cc: caml-list, ocaml_beginners

On Tue, Aug 03, 2004 at 06:46:12PM +0400, Paul Argentoff wrote:
> 
> Hello World!
> 
> Can anyone answer my silly question: what does "let () = bla" really mean?

It means "evaluate 'bla' now".  In this instance, 'bla' is assumed to
be something which evaluates to / returns '()' (ie. the unit value).

There is another related syntax:

let _ = bla

which evaluates 'bla', and ignores the return type of 'bla', whatever
it might be.

Basically, these constructs are a way to evaluate something at
initialization time - usually when the program starts up, or the
module is loaded by some other means such as Dynlink.

These two syntaxes are equivalent:

let _ =
  f1 ();
  f2 ();
  f3 ()

and:

f1 ();;
f2 ();;
f3 ();;

The first is used by people who don't like the ';;' syntax.

I've CC'd this message to ocaml-beginners
[http://groups.yahoo.com/group/ocaml_beginners/] which is a more
appropriate place to discuss this stuff.

Rich.

-- 
Richard Jones. http://www.annexia.org/ http://www.j-london.com/
Merjis Ltd. http://www.merjis.com/ - improving website return on investment
PTHRLIB is a library for writing small, efficient and fast servers in C.
HTTP, CGI, DBI, lightweight threads: http://www.annexia.org/freeware/pthrlib/

-------------------
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/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] let () =
  2004-08-03 14:46 [Caml-list] let () = Paul Argentoff
  2004-08-03 15:09 ` Yann Regis-Gianas
  2004-08-03 15:10 ` Richard Jones
@ 2004-08-03 15:11 ` John Prevost
  2004-08-03 17:08 ` Nicolas Cannasse
  3 siblings, 0 replies; 6+ messages in thread
From: John Prevost @ 2004-08-03 15:11 UTC (permalink / raw)
  To: Ocaml Mailing List

It really means "I expect bla to have type unit, and am executing it
here for side effects."  Some people write instead:

let _ = bla

Which means "I don't care what type bla has, but am executing it for
side effects."  The let () one is somewhat safer because you are
explicitly saying you don't expect the call to return anything.  The _
one, you might leave an argument out, and it would still typecheck.

JOhn.

-------------------
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/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] let () =
  2004-08-03 14:46 [Caml-list] let () = Paul Argentoff
                   ` (2 preceding siblings ...)
  2004-08-03 15:11 ` John Prevost
@ 2004-08-03 17:08 ` Nicolas Cannasse
  2004-08-04 10:14   ` Keith Wansbrough
  3 siblings, 1 reply; 6+ messages in thread
From: Nicolas Cannasse @ 2004-08-03 17:08 UTC (permalink / raw)
  To: caml-list, Paul Argentoff

> Hello World!
>
> Can anyone answer my silly question: what does "let () = bla" really mean?

let () = bla is equivalent to writing bla; but is opening a block if
followed by an 'in'.

Here are the different forms :

bla; (* warning if partial application or if returned type not unit *)
ignore(bla); (* warning if partial application, ignore returned type *)
let () = bla (* error if partial application or if returned type not unit *)
let _ = bla (* no warning or errors !! be careful if you want to use it *)

Regards,
Nicolas Cannasse

-------------------
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/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] let () =
  2004-08-03 17:08 ` Nicolas Cannasse
@ 2004-08-04 10:14   ` Keith Wansbrough
  0 siblings, 0 replies; 6+ messages in thread
From: Keith Wansbrough @ 2004-08-04 10:14 UTC (permalink / raw)
  To: Nicolas Cannasse; +Cc: caml-list, Paul Argentoff

> Here are the different forms :
> 
> bla; (* warning if partial application or if returned type not unit *)
> ignore(bla); (* warning if partial application, ignore returned type *)
> let () = bla (* error if partial application or if returned type not unit *)
> let _ = bla (* no warning or errors !! be careful if you want to use it *)

let (_:bool) = bla (* error if partial application or if returned type not bool *)

is also very handy.

--KW 8-)
-- 
Keith Wansbrough <kw217@cl.cam.ac.uk>
http://www.cl.cam.ac.uk/users/kw217/
University of Cambridge Computer Laboratory.

-------------------
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/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

end of thread, other threads:[~2004-08-04 10:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-03 14:46 [Caml-list] let () = Paul Argentoff
2004-08-03 15:09 ` Yann Regis-Gianas
2004-08-03 15:10 ` Richard Jones
2004-08-03 15:11 ` John Prevost
2004-08-03 17:08 ` Nicolas Cannasse
2004-08-04 10:14   ` Keith Wansbrough

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