Live data from Hacker News

Ask Hackers: Opinions on OCaml?

news.ycombinator.com

31–40 of 42 posts

Re: Ask Hackers: Opinions on OCaml?

#31
post #27
post #21

Steve Yegge, who you're quoting as being in favor of OCaml, has since implied that he found it lacking on closer inspection, but, uncharacteristically, without writing at length about it.

At the top of his follow on article he says it isn't good for server applications, but he'd use it for client side.

Yeah, here's the quote: "(Note, long after I wrote this entry: I think OCaml has some fairly fundamental problems that keep it from being a first choice for server-side development. If I were to use it for anything, it would be as a substitute for C++ in delivering client-side executable/GUI programs, e.g. for Windows systems. And I still think it's a really cool language.)"

Anyone know what he's referring to?

Re: Ask Hackers: Opinions on OCaml?

#32
post #13

I've been using it a lot, and I really love it. It's the only language I've used in which I found static types to be worth it (I don't count C, as its type system is badly broken, and iss only there to counter some of the language's runtime limitations). If your problem can be presented as advanced data structures, it's really the right tool for the job. Unless if your problem is purely functional, then maybe in Hask…

Upmod for the great point - OCaml's niche is advanced data structures.

Re: Ask Hackers: Opinions on OCaml?

#33
post #15

I love OCaml. It's Lisp + syntax + type safety + speed. Lots of speed. Theoretically, I know that Lisp is a more expressive language, but I always find myself programming in OCaml anyway--perhaps just because the code is easier for me to read. I don't know why OCaml gets so little attention (and such bitter hatred from a few people), but maybe it's because its merits are mundane: it focuses on doing things right, rat…

Yeah, I see it as a happy medium between the practical world and the form of programming - an Aristotelian language, if you will.

It's nice when the philosophers come down to rescue us from our cave.

Re: Ask Hackers: Opinions on OCaml?

#34
post #2

I've used it. I think OCaml would be a big win if you have your software designed all up front, and need to verify that it works correctly, e.g., avionics software. Unfortunately, avionics software development seems to be moving toward C/C++...

It blows my mind that in 2008 companies are moving toward C++.

Go&learn C++. It blows my mind how often people confuse C++ with "C with classes" in 2008. Granted, C++ isn't as sexy as OCaml, but it's still C plus some rather nice extentions that (finally) got trully portable and work as advertised.

Powerful templates plus multiple inheritance give you a very impressive weapon to play with. C# and Java don't even come close.

And please... 99% of software on Windows, Mac OS X and Linux are built using the same stuff: C/C++/ObjectiveC.

Re: Ask Hackers: Opinions on OCaml?

#35
post #22

What's a problem is that there aren't any good books about it. Practical OCaml was almost universally panned, so I skipped it. I'd love a good book on OCaml or Haskell.

The best way to learn Haskell is a combination of #haskell on irc.freenode.net and the Haskell wikibook (incomplete and often flaky, but up until the beginning of the Advanced section, a very nice introduction to the language)

Re: Ask Hackers: Opinions on OCaml?

#37
Here's my favorite open-source OCaml application: http://www.cis.upenn.edu/~bcpierce/unison

Unison is a file-synchronization tool for Unix and Windows. It allows two replicas of a collection of files and directories to be stored on different hosts (or different disks on the same host), modified separately, and then brought up to date by propagating the changes in each replica to the other.

It's also listed as one of the OCaml "success stories" here: http://caml.inria.fr/about/successes.en.html

Subversion access details here: http://www.seas.upenn.edu/~bcpierce/unison/svn-instructions....

The author has several papers on it and data synchronization in general here: http://www.cis.upenn.edu/~bcpierce/papers/index.shtml#Synchr...

Re: Ask Hackers: Opinions on OCaml?

#38
post #29
post #25

I've written between 50 and 100KLoCs of OCaml code over the last year (before that, I did mostly C and Ruby, which I've been using since 2002; touched many other languages but never did anything significant, over 5-10,000 lines with them). If I had to describe the language in two words, I'd say that it's practical and loyal. It's a loyal language because it doesn't bite you in the ass when you don't expect it. It's p…

The back in time ability sounds pretty cool. I've wondered whether any debuggers implement that idea. I also like the idea of an extensible grammar (and syntax too, right?) I think pg should allow arc's syntax to be extended; which I remember him saying he'd do somewhere, but I haven't been able to find the quote since.

" I also like the idea of an extensible grammar (and syntax too, right?)"

Yes, that's what I meant (you change the grammar, resulting in new syntax).

Some examples of what you can do with camlp4:

http://martin.jambon.free.fr/pa_memo.ml allows to define memoized functions very conveniently:

    (* normal *) 
    let fib = function 0 | 1 -> 1 | n -> fib (n-1) + fib (n-2)
    (* memoized *)
    let fib = memo 0 | 1 -> 1 | n -> fib (n-1) + fib (n-2)
Automatic generation of

* typed JSON marshallers (http://martin.jambon.free.fr/json-static.html)

    type json mytype = Foo | Bar of int * int
    (* just add "json" to the type declaration to create to
       create the json_of_mytype and mytype_of_json functions *)
* serialization with S-expressions (http://www.janestcapital.com/ocaml/)

* pretty-printing, type-safe marshalling with structure-sharing, dynamic typing, equality... (http://code.google.com/p/deriving/)

* list comprehensions, heredocs, string interpolation, lazy pattern matching, "do syntax" for monads (very much like Haskell's)...

Here's some OCaml code that relies on a rather large syntax extension of mine which allows you to generate (or verify) SQL schemas automatically and build composable queries using a typed relational algebra (the type system ensures that all queries are valid; if you change the schema and break some queries, the compiler will tell you what's wrong --- broken queries just don't compile):

   TABLE user users
     COLUMN id SERIAL AUTO PRIMARY KEY
     COLUMN name VARCHAR(64) UNIQUE
     COLUMN age INT NULLABLE INDEXED
     COLUMN password VARCHAR(64)
   END
   
   TABLE comment comments
     COLUMN id SERIAL AUTO PRIMARY KEY
     COLUMN title TEXT
     COLUMN text TEXT
     COLUMN created_at TIMESTAMPZ
     COLUMN author SERIAL FOREIGN(users, id)
   END
   
   let minors x = SELECT [User_age 
You can read more about this extension at http://eigenclass.org/hiki/typed-relational-algebra-in-OCaml

Re: Ask Hackers: Opinions on OCaml?

#39
post #31
post #27

Earlier quoted context omitted.

At the top of his follow on article he says it isn't good for server applications, but he'd use it for client side.

Yeah, here's the quote: "(Note, long after I wrote this entry: I think OCaml has some fairly fundamental problems that keep it from being a first choice for server-side development. If I were to use it for anything, it would be as a substitute for C++ in delivering client-side executable/GUI programs, e.g. for Windows systems. And I still think it's a really cool language.)" Anyone know what he's referring to?

Maybe the lack of parallelism in OCaml's threads at the time he wrote that?

There are now at least two solutions to obtain speedups on multi-core and multi-processor machines plus scalability by allowing seamless distributed processing: the JoCaml extension, which integrates the join calculus (http://jocaml.inria.fr/), and coThreads (http://cothreads.sourceforge.net/), which comprises shared-memory (with extensions like STM) and message passing while keeping backwards-compatibility with the original Threads library.

Re: Ask Hackers: Opinions on OCaml?

#40
post #34

Earlier quoted context omitted.

It blows my mind that in 2008 companies are moving toward C++.

Go&learn C++. It blows my mind how often people confuse C++ with "C with classes" in 2008. Granted, C++ isn't as sexy as OCaml, but it's still C plus some rather nice extentions that (finally) got trully portable and work as advertised. Powerful templates plus multiple inheritance give you a very impressive weapon to play with. C# and Java don't even come close. And please... 99% of software on Windows, Mac OS X and…

I'm not sure I'd lump Objective-C in with C++ :/

C# and VB run an awful lot of Windows software, too.

Post reply on HN