From: Matt Gushee <mgushee@havenrock.com>
To: caml-list@pauillac.inria.fr
Subject: Re: [Caml-list] Frustrated Beginner
Date: Mon, 22 Dec 2003 22:34:51 -0700 [thread overview]
Message-ID: <20031223053451.GB1145@swordfish> (raw)
In-Reply-To: <29911.24.6.3.124.1072153159.squirrel@www.cs.fiu.edu> <1072152186.59938.30.camel@tylere>
On Mon, Dec 22, 2003 at 11:03:07PM -0500, Tyler Eaves wrote:
>
> I'm a 19 yr old computer science student, been programming for perhaps
> 10 years. ...
Welcome! I'm at best an intermediate OCaml programmer, but I'll try to
make a helpful suggestion or two.
> So why is O'Caml giving me so much trouble?
Do you have any previous experience with functional programming (FP), or
have you studied FP in school? If not, then you're learning both a new
syntax and a very different programming paradigm at once, so you should
expect a steep learning curve. But I think if you stick with it, after a
while it will all start to make sense, and you'll be glad you made the
effort.
> I've been trying to pick it up for about a week now, read various
> online tutorials.
Which ones? Personally, I have found David Matuszek's and Richard Jones'
tutorials to be the most helpful for learning fundamentals.
http://www.csc.vill.edu/~dmatusze/resources/ocaml/ocaml.html
http://www.merjis.com/richj/computers/ocaml/tutorial/
> My biggest source of problems seems to be the syntax. I'm totally
> confused as far as ; vs ;; vs nothing, ...
Yes, that is a bit tricky. You've undoubtedly read explanations of the
semicolons, but sometimes it helps if you get the same information again
in slightly different terms, so let me try:
* A double semicolon ends a "sentence"--that is, it terminates a
top-level construct such as a function definition--but not nested
function definitions, because they're not "sentences," they're
"phrases".
You can omit ;; in most cases, but I would suggest at first using
it everywhere it is allowed. When you omit the ;; and there is a
syntax error in your code, the compiler often goes many lines past
the real trouble spot before it detects an error, so using ;;
everywhere can narrow down your search.
* The single semicolon is perhaps a bit harder to understand, but I
think it helps to keep in mind that OCaml is basically a functional
language, yet it also supports imperative programming. Being
functional means that there are no statements per se. It's all about
evaluating expressions, and *every* expression returns a value.
However, there are expressions that are functionally equivalent to
statements. In order to conform to the functional model, they have
to return a value, but there is no useful value to return. So they
return the unit value, '()'.
Basically, whenever you are programming imperatively--when you have
one of these pseudo-statements that return (), and when it this
imperative phrase is not the final result of a function, you need to
separate it from the following phrase with a single semicolon. A
simple example:
match foo with
| None -> print_endline "Nothing"; ""
| Some x -> print_endline x; x
This expression returns a string, but before returning, you want to
print a message. Printing functions, of course, return ().
Hope this helps a bit. Best of luck to you!
--
Matt Gushee When a nation follows the Way,
Englewood, Colorado, USA Horses bear manure through
mgushee@havenrock.com its fields;
http://www.havenrock.com/ When a nation ignores the Way,
Horses bear soldiers through
its streets.
--Lao Tzu (Peter Merel, trans.)
-------------------
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
next prev parent reply other threads:[~2003-12-23 5:34 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 [this message]
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
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=20031223053451.GB1145@swordfish \
--to=mgushee@havenrock.com \
--cc=caml-list@pauillac.inria.fr \
/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