OT: Ocaml?

P

Paul Rubin

Anyone here use OCAML? How do you like it? Is it a language a
Pythonista can learn to love? From what little I've seen, it looks
interesting, but I haven't actually tried installing or using it yet.
 
G

Graham Breed

Paul said:
Anyone here use OCAML? How do you like it? Is it a language a
Pythonista can learn to love? From what little I've seen, it looks
interesting, but I haven't actually tried installing or using it yet.

Yes, I've been playing with it. It's a good complement to Python in
that it's statically typed with an efficient compiler. It has an
interactive interpreter, but there are some cases where it feels lower
level. Like you can't do introspection to the same extent, and it
doesn't have the magic string formatting (or rather, it must for the
interpreter, but I don't know how to get at it).


Graham
 
D

Donn Cave

Quoth Paul Rubin <http://[email protected]>:
|>> Anyone here use OCAML? How do you like it? Is it a language a
|>> Pythonista can learn to love? From what little I've seen, it looks
|>> interesting, but I haven't actually tried installing or using it yet.
|> Yes and I think it's a great language, but it's a little bit harder
|> to start learning it. (you must learn how to read the types).
|> But you get a very 'save' language with a very efficient compiler.
|
| Do you find that the strict type system gets in your way like it does
| in Java?

I have used ocaml only casually, and Java never, but one thing
that has worked for me is sort of a functional counterpart of
OOP, ``partial application.''

let multiply a b = a * b
let double = multiply 2

So supposing I want something like Python's file object.

let read_file fp sz = ...
let write_file fp data sz = ...
let make_file_file fp =
{
read = read_file fp;
write = write_file fp
}
let f = make_file_file (open filename) in
let data = f.read 512
...

let read_buffer buffer sz = ...

The point being that the type system, though probably stricter
than Java's, does allow ways to conveniently implement the same
interface for radically different types, in this case with a
feature that's just a basic natural part of any functional
programming language. Maybe Java could do the same?

Then there is a lot of stuff in Objective CAML's module system
that directly addresses type issues, and it also has a fairly
complicated OOP system.

Donn Cave, (e-mail address removed)
 
D

Daniel Yoo

:> > Anyone here use OCAML? How do you like it? Is it a language a
:> > Pythonista can learn to love? From what little I've seen, it looks
:> > interesting, but I haven't actually tried installing or using it yet.
:> Yes and I think it's a great language, but it's a little bit harder
:> to start learning it. (you must learn how to read the types).
:> But you get a very 'save' language with a very efficient compiler.

: Do you find that the strict type system gets in your way like it does
: in Java?


Actually, not at all! Mark Jason Dominus has written a very nice page
talking about type systems, and in particular, gushes about the
ML/Ocaml approach. He shows how the ML type system just gets out of
the way:

http://perl.plover.com/yak/typing/

Very good reading. *grin*


Hope this helps!
 
D

Donn Cave

Paul Rubin said:
Anyone here use OCAML? How do you like it? Is it a language a
Pythonista can learn to love? From what little I've seen, it looks
interesting, but I haven't actually tried installing or using it yet.

I think typically, people who like Python tend to say they
like Haskell more often than Objective CAML. Haskell is
more similar in one very superficial respect - its layout
notation is like Python's indented notation - but it's
basically much farther from Python in terms of fundamental
notions about programming. So it's different in interesting
ways. Haskell is pretty, on a couple of different levels.
Ocaml is by comparison efficient, portable, fast, predictable,
but I have to say Objective CAML is one of the ugliest languages
I ever saw - regrettable syntax, baroque core language, awkward
support for basic data types like strings and numbers. (So for
me it's worth making a distinction between ocaml, which I think
is brilliant, and Objective CAML the sorry language it implements.)

Incidentally, a few years back someone got fairly far along on
implementing Python (or something like it) from scratch in
Objective CAML.

Donn Cave, (e-mail address removed)

(What about that syntax complaint - just my inflexible esthetic
taste, maybe? Consider this, you decide:

let jump d v = begin
match d with
UP -> begin
output_string stdout "Jump up\n";
match v with
0 -> nonjump ()
| _ -> jumpup v
end
| DOWN -> begin
output_string stdout "Jump down\n";
match v with
0 -> nonjump ()
| _ -> jumpdown v
end;
output_string stdout "done jumping\n"
end
;;
jump UP 3

Would you expect "done jumping"? Objective CAML's syntax for
a procedural block is expressions separated by ";", optionally
enclosed in "begin"/"end" or parentheses. The DOWN branch
starts with a begin/end block, but it's utterly ambiguous
whether the semicolon that follows that block starts a new
expression in the DOWN branch, or in the function block.
The compiler actually does the former. Because begin/end is
optional for blocks, in practice you have to put it around
single expressions like match UP/DOWN here, and that's annoying
and counter-intuitive.)
 
M

Michael Hudson

Donn Cave said:
Incidentally, a few years back someone got fairly far along on
implementing Python (or something like it) from scratch in
Objective CAML.

That was John Max Skaller, and the code is still on sf:

http://vyper.sf.net

If you're really curious and the anon CVS isn't working, I can stick a
tarball somewhere.

Cheers,
mwh

--
> The conversion rate from Imperial Shitloads to Metric Shitloads is
> to multiply by 1.07. Which you multiply is left as an exercise.
Both.
-- Bob McCown & Jasper Janssen, asr
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,167
Latest member
SusanaSwan
Top