From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA17575; Tue, 23 Dec 2003 17:07:46 +0100 (MET) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA18111 for ; Tue, 23 Dec 2003 17:07:45 +0100 (MET) Received: from guestc.h0020780e8acd.ne.client2.attbi.com (h0020780e8acd.ne.client2.attbi.com [24.61.94.47]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id hBNG7ib17492 for ; Tue, 23 Dec 2003 17:07:44 +0100 (MET) Received: from guestc.h0020780e8acd.ne.client2.attbi.com (localhost.localdomain [127.0.0.1]) by guestc.h0020780e8acd.ne.client2.attbi.com (8.12.8/8.12.8) with ESMTP id hBNGBJme001911; Tue, 23 Dec 2003 11:11:19 -0500 Received: from localhost (bhurt@localhost) by guestc.h0020780e8acd.ne.client2.attbi.com (8.12.8/8.12.8/Submit) with ESMTP id hBNGBJ0P001907; Tue, 23 Dec 2003 11:11:19 -0500 X-Authentication-Warning: guestc.h0020780e8acd.ne.client2.attbi.com: bhurt owned process doing -bs Date: Tue, 23 Dec 2003 11:11:19 -0500 (EST) From: Brian Hurt X-X-Sender: bhurt@guestc.h0020780e8acd.ne.client2.attbi.com To: Tyler Eaves cc: caml-list@inria.fr Subject: Re: [Caml-list] Frustrated Beginner In-Reply-To: <1072152186.59938.30.camel@tylere> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 python:01 langauges:01 python:01 gui:01 analogy:01 cultures:99 disambiguate:01 replacements:01 parens:01 postion:99 ocaml's:01 bug:01 char:01 recursion:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk I notice a lot of replies to this already, I'll add mine. On Mon, 22 Dec 2003, Tyler Eaves wrote: > First a bit of background: > > I'm a 19 yr old computer science student, been programming for perhaps > 10 years. Started (Like so many did in the early '90s with QBasic in > DOS. These days most of my work is done in either PHP (web stuff) or > Python (everything else) with the occasional bit of C for stuff that > needs to run really fast. I'm also passingly familiar with a number of > other langauges (C++, Java, Perl, etc). > > So why is O'Caml giving me so much trouble? I've been trying to pick it > up for about a week now, read various online tutorials. I'm just having > no luck at all. My largest program to date (that works) is all of 3 > lines long, and simply printed out the command line arguments passed to > the program. All programming languages are not the same. There programming "paradigms"- literally different ways of thinking about programming. Imperitive/Procedural (C, most Perl, etc) is one way of thinking about things. Object Oriented (Python, Java, C++, etc) is another. Functional (Lisp, Scheme, Ocaml) is a third. Picking up a new language in a paradigm you are already familiar with is easy- if you know C++ and Java, picking up Python or Ruby is a week or three at most, no problem. Picking up a language in a different paradigm is much harder- not only do you have to pick up a new syntax, you have to pick up a new way of thinking about programming. It's worth the effort, IMHO. Some problems are easier to implement in some paradigms than other (take a look at Motif programming to get a deeper appreciation of OO for GUI libraries). Perl, Python, and (IIRC) Ruby all give you some ability to write functional code. Things you learn in Ocaml are applicable elsewhere (not to mention the fact that you get to use Ocaml). To use an analogy, if you know English, learning German or French (while a little hard) isn't that difficult, but the cultures share a common concept base. You have to learn a new syntax and a new vocabulary, but very few new concepts. Learning Chinese or Navaho is a lot more difficult, because not only do you have the problems of learning German or French, but you also have to learn concepts, new ways of thinking. > > My biggest source of problems seems to be the syntax. I'm totally > confused as far as ; vs ;; vs nothing, when to use ( ), and things of > the like. This took some rethinking on my part as well. The trick is to remember that ';' is an operator, like '+' and '.' are. Actually, the best comparison is with the comma operator in C. If the type of '+' is int -> int -> int ('+' takes two int parameters and returns an int), then the type of the ';' operator is unit -> 'a -> 'a (or more correctly, 'a -> 'b -> 'b). One you start thinking of ';' as an operator and not a statement seperator, it becomes more obvious that an ocaml function body is simply a single expression, and not a series of statements. ';;' is more close to what ';' in most languages mean- it's what ends an expression. When do you use parenthesis? The same times you'd use them in any other language- to disambiguate expressions. Note that begin/end are replacements for parens, and occassionally look nicer. > It doesn't help that the compiler is completly naive when it > comes to Syntax Errors. It would be so helpful if it could give an error > message that actually told the programmer what it expected. I realise > that O'Camls syntax allows many things, so that it may be hard to say > exactly what it WAS expecting in all cases, but surely SOMETHING > meaningful, besides a charater postion could be given? Heh. I've got to agree that Ocaml's error messages leave something to be desired. But, speaking with 15 years more programming experience, there will come a time when you will give your left arm to be magically told just the line number of the bug. Simple experience with the language helps here. I find myself more easily being able to diagnose what Ocaml is really complaining about the more I use a language. Of course, this is true of any language. > > What I'd really like is a site with examples of actual programs. Most of > the example code I've seen is A: Not commened and B: Recursive > Mathematical functions. I'd really love to see an example, of say, > reading in a file, looking at each character, and doing something when > it encounters, say, a tab. Or any other such program that actually does > something. Except how you write a program to do exactly that in Ocaml is to write a recursive mathematical function: let count_tabs ins = let rec loop cnt = let eof, c = try false, (input_char ins) with | End_of_file -> true, ' ' in if eof then cnt else if (c = '\t') then loop (cnt + 1) else loop cnt in loop 0 ;; Learn recursion. It's an incredibly powerful concept, and it's usefull in almost every language. Including mathematics. > > I really want to like O'Caml. It seems to offer a very nice feature set, > and the ability to compile to super-fast native code is the icing on the > cake. Right now though, I'm frustrated and on the verge of giving up. > Don't give up. You're learning more than just a new programming language. -- "Usenet is like a herd of performing elephants with diarrhea -- massive, difficult to redirect, awe-inspiring, entertaining, and a source of mind-boggling amounts of excrement when you least expect it." - Gene Spafford Brian ------------------- 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