From: skaller <skaller@ozemail.com.au>
To: Tyler Eaves <tyler@ml1.net>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Frustrated Beginner
Date: 24 Dec 2003 20:49:47 +1100 [thread overview]
Message-ID: <1072259385.2702.43.camel@pelican> (raw)
In-Reply-To: <1072152186.59938.30.camel@tylere>
On Tue, 2003-12-23 at 15:03, Tyler Eaves wrote:
> So why is O'Caml giving me so much trouble?
Because the syntax is foreign.
> My biggest source of problems seems to be the syntax. I'm totally
> confused as far as ; vs ;; vs nothing,
Yeah. The 'top level' is syntactically and semantically different
to the inner levels of Ocaml.
(1) At the top level you can write a sequence of definitions
or evaluate a sequence of expressions. This is not possible
anywhere else.
(2) If the definition/expression starts with a keyword
you don't need to use ';;' before it. For example:
let f x = x
let g x = x * x
;; (* needed because .. *)
f x * g x (* no keyword starts this *)
;; (* needed to force evaluation of expression NOW *)
At the inner level, you cannot write
let h x =
let f x = x
let g x = x * x
;;
f x * g x
;;
Inner expressions are evaluated 'entirely', not one at a time like
the top level. So you must write this:
let h x =
let f x = x in
let g x = x * x in
f x * g x
;; (* end top level definition *)
You use ';' for sequencing evaluations:
print_endline "Hello";
print_endline "World"
;;
This is a *single* expression evaluated, whereas
print_endline "Hello"
;;
print_endline "World"
;;
is two evaluations. (Try this in the 'ocaml' interpreter).
> when to use ( ), and things of
> the like. It doesn't help that the compiler is completly naive when it
> comes to Syntax Errors.
The reason is: the parser is a Yacc tool which means it
uses a LR parsing technique. When it can't parse something,
it has no choice than to say 'syntax error'. Its an error,
there's no way to say what the error is.
One way around this in LR parsers is to include error
productions in the grammar... that is, make the parser
parse common errors.
Another way, is to parse something more general than
permitted first, then check constraints. This is certainly
done with type checking for example.
-------------------
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
prev parent reply other threads:[~2003-12-24 9:49 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-12-23 4:03 Tyler Eaves
2003-12-23 4:19 ` jayanta nath
2003-12-23 5:34 ` Matt Gushee
2003-12-23 6:11 ` Tyler Eaves
2003-12-23 6:21 ` Michael Vanier
2003-12-23 6:31 ` Michael Jeffrey Tucker
2003-12-23 12:16 ` Richard Jones
2003-12-23 20:23 ` Dustin Sallings
2003-12-23 6:32 ` Shawn Wagner
2003-12-23 6:43 ` Matt Gushee
2003-12-23 5:58 ` Dustin Sallings
[not found] ` <EAEE2FF2-3510-11D8-B3A1-000A9584A16E@ml1.net>
2003-12-23 6:53 ` Dustin Sallings
2003-12-23 7:23 ` Tyler Eaves
2003-12-23 8:26 ` Dustin Sallings
2003-12-23 6:20 ` Tom Murray
2003-12-23 8:52 ` Stefano Zacchiroli
2003-12-23 16:47 ` [Caml-list] Ocaml syntax David Brown
2003-12-23 20:19 ` Dustin Sallings
2003-12-23 21:03 ` Eric Merritt
2003-12-23 21:52 ` brogoff
2003-12-24 10:27 ` skaller
2003-12-24 11:42 ` Peter Jolly
2003-12-24 12:19 ` skaller
2003-12-30 8:14 ` dmitry grebeniuk
2003-12-30 17:48 ` David Brown
2003-12-23 10:26 ` [Caml-list] Frustrated Beginner Samuel Lacas
2003-12-23 11:01 ` Dustin Sallings
2003-12-23 14:34 ` Oleg Trott
2003-12-23 20:25 ` Dustin Sallings
2003-12-23 16:11 ` Brian Hurt
2003-12-23 16:20 ` Sven Luther
2003-12-23 16:52 ` David Brown
2003-12-23 20:32 ` Dustin Sallings
2003-12-24 10:41 ` Issac Trotts
2003-12-23 17:39 ` Brian Hurt
2003-12-24 9:35 ` Jacques Garrigue
2003-12-24 9:49 ` skaller [this message]
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=1072259385.2702.43.camel@pelican \
--to=skaller@ozemail.com.au \
--cc=caml-list@inria.fr \
--cc=tyler@ml1.net \
/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