
Hi all, Okay, I've been studying Haskell for a few days and I think I have a feel for the language. I completted a course, and wrote a Revers Polish Notation calculator. Now that I sort of understand Haskell, I was hoping someone could give me an opinion on OCaml from a Haskell POV. Both are functional and have fairly clear syntax. OCaml is supposed to be very fast, and Haskell perhaps is not. Besides that, what else could you say about them? What would make someone prefer one over the other? Any thoughts, opinions and comments would be most appreciated. Thanks! Cheers, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/ I am not over-weight, I am under-tall. /

You'll probably get a lot of different answers. I think the major difference is the notion of encapsulation used by each. Haskell has type classes and O'Caml has structures/functors and (OO) classes. I personally find type class much nicer. Additionally, I think Haskell's syntax is easier on the eyes and the libraries are much more well established. That said, I use O'Caml for all of my non-Perl coding. Why? Because I need lots of arrays and though Haskell does support them, the lack of syntactic sugar makes it very inconvenient. Second, lack of loop support, which I can live without. Finally, it's slower. I would forgive the last (it can be made faster if you use unboxed arrays and so on) if the first two were fixed. (Of course, which is better depends strongly on your application. I do a lot of statistical machine learning stuff, which requires processing of huge arrays and matrices, lots of loops and lots of funny math calculations.) On Sat, 24 Dec 2005, Daniel Carrera wrote:
Hi all,
Okay, I've been studying Haskell for a few days and I think I have a feel for the language. I completted a course, and wrote a Revers Polish Notation calculator.
Now that I sort of understand Haskell, I was hoping someone could give me an opinion on OCaml from a Haskell POV. Both are functional and have fairly clear syntax. OCaml is supposed to be very fast, and Haskell perhaps is not. Besides that, what else could you say about them? What would make someone prefer one over the other?
Any thoughts, opinions and comments would be most appreciated.
Thanks!
Cheers, Daniel.
-- Hal Daume III | hdaume@isi.edu "Arrest this man, he talks in maths." | www.isi.edu/~hdaume

Hal, What is the syntactic sugar that you are lacking with arrays? Also, do loops matter if they can be emulated with recursion? Thanks, Joel On Dec 24, 2005, at 12:46 AM, Hal Daume III wrote:
That said, I use O'Caml for all of my non-Perl coding. Why? Because I need lots of arrays and though Haskell does support them, the lack of syntactic sugar makes it very inconvenient. Second, lack of loop support, which I can live without. Finally, it's slower. I would forgive the last (it can be made faster if you use unboxed arrays and so on) if the first two were fixed.

Hal Daume III wrote:
That said, I use O'Caml for all of my non-Perl coding. Why? ... Second, lack of loop support,
Lack of loop support? You mean like while loops and for loops? This suggests that some problems are easier to solve with loops than using lists and recursion.
(Of course, which is better depends strongly on your application. I do a lot of statistical machine learning stuff, which requires processing of huge arrays and matrices, lots of loops and lots of funny math calculations.)
I see. Thanks for the info. Very interesting. Cheers, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/ I am not over-weight, I am under-tall. /

On Sat, Dec 24, 2005 at 12:35:21AM +0000, Daniel Carrera wrote:
Now that I sort of understand Haskell, I was hoping someone could give me an opinion on OCaml from a Haskell POV. Both are functional and have fairly clear syntax. OCaml is supposed to be very fast, and Haskell perhaps is not.
When it comes to Haskell, speed is mostly an implementation issue. Of course, there are many problems with making Haskell programs run fast, but on the other hand there are also many opportunities. For example recent developments of GHC promise that Haskell will be one of the best languages to use on SMP / multicore systems.
Besides that, what else could you say about them? What would make someone prefer one over the other?
There are many differences (Haskell on the left): - strict (with strictness annotations) / non-strict (with some support for laziness) [read http://www.md.chalmers.se/~rjmh/Papers/whyfp.html to see why it matters] - pure / impure - both have a type system based on Hindley-Milner, but with radically different extensions (type-classes, GADTs vs. objects, polymorphic variants, labelled function parameters) - different module systems (simple in Haskell, full-blown in OCaml (but can be emulated in Haskell)) Some subjective differences: - functional / imperative (:-)) - higher order DSLs (monads, combinator libraries) are easy to define and use / are a bit cumbersome - pretty / ugly Best regards Tomasz -- I am searching for a programmer who is good at least in some of [Haskell, ML, C++, Linux, FreeBSD, math] for work in Warsaw, Poland

Tomasz Zielonka wrote:
When it comes to Haskell, speed is mostly an implementation issue. Of course, there are many problems with making Haskell programs run fast, but on the other hand there are also many opportunities. For example recent developments of GHC promise that Haskell will be one of the best languages to use on SMP / multicore systems.
So we can expect Haskell to get faster as GHC evolves and multicore systems becomre more common...
There are many differences (Haskell on the left): - pure / impure
Let's see if I understand this one. Haskell and OCaml both treat functions as first class objects, including the ability to pass functions as arguments or return functions. But OCaml allows you to change the value of a variable and that's what makes it impure. Yes? Does this mean that it's harder to prove an OCaml program correct? Or that you have to be careful to not accidentally change the value of variables? I've taken a glance at an OCaml tutorial, and the syntax looks a little more difficult than Haskell's (e.g. "rec" for recursive functions).
- pretty / ugly
:-) Cheers, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/ I am not over-weight, I am under-tall. /

On Sat, Dec 24, 2005 at 03:11:06PM +0000, Daniel Carrera wrote:
Tomasz Zielonka wrote:
There are many differences (Haskell on the left): - pure / impure
Let's see if I understand this one. Haskell and OCaml both treat functions as first class objects, including the ability to pass functions as arguments or return functions. But OCaml allows you to change the value of a variable and that's what makes it impure. Yes?
More precisely, it allows to change/access mutable variables as part of expression evaluation.
Does this mean that it's harder to prove an OCaml program correct? Or that you have to be careful to not accidentally change the value of variables?
Both, actually. Best regards Tomasz -- I am searching for a programmer who is good at least in some of [Haskell, ML, C++, Linux, FreeBSD, math] for work in Warsaw, Poland

Tomasz Zielonka wrote:
When it comes to Haskell, speed is mostly an implementation issue.
I just took another look at this. By "implementation issue" do you mean the person who implements the compiler or the program being compiled? If the latter... other emails here suggest that writing an efficient Haskell program is a difficult task :-( Cheers, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/ I am not over-weight, I am under-tall. /

From: Daniel Carrera
To: Haskell-Cafe@haskell.org Subject: Re: [Haskell-cafe] Haskell vs OCaml Date: Sat, 24 Dec 2005 20:07:00 +0000 Tomasz Zielonka wrote:
When it comes to Haskell, speed is mostly an implementation issue.
I just took another look at this. By "implementation issue" do you mean the person who implements the compiler or the program being compiled? If the latter... other emails here suggest that writing an efficient Haskell program is a difficult task :-(
I've found that Haskell is pretty good in implementing recursive algorithms. Problem cames when one want's to implement non recursive algorithm by terms of recursion as Haskell does not support loops. Perhaps if we can get loops, situation will improve, but then that wouldn't be functional style. Try for example to implement recursive calculation of matrix determinant in some classic imperative language and in Haskell on large matrix, or compare performance of recursive descent parser implemented in Haskell and language which does not handles recursion so well as Haskell. Other problem is that Haskell data is lazy and optimised for size rather then speed. One have to use non lazy structures in order to compete with imperative languages speed combined with non recursive algo's. Difficulty came when one has to utilize Haskell advantages and reduce much as possible disadvantages. After all you can peek and poke over Ptr's same as in C which will give you speed as in C :) (I've tried that works well as I used to peek/poke:) Greetings, Bane. _________________________________________________________________ FREE pop-up blocking with the new MSN Toolbar - get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/

Branimir Maksimovic wrote:
I've found that Haskell is pretty good in implementing recursive algorithms. Problem cames when one want's to implement non recursive algorithm by terms of recursion as Haskell does not support loops. Perhaps if we can get loops, situation will improve, but then that wouldn't be functional style.
Could you give an example of a loop you find awkward in Haskell? I've often found that you can just define a control construct in Haskell when needed (e.g., some kind of loop). -- Lennart

From: Lennart Augustsson
To: Branimir Maksimovic CC: daniel.carrera@zmsl.com, Haskell-Cafe@haskell.org Subject: Re: [Haskell-cafe] Haskell vs OCaml Date: Sun, 25 Dec 2005 10:25:44 +0100 Branimir Maksimovic wrote:
I've found that Haskell is pretty good in implementing recursive algorithms. Problem cames when one want's to implement non recursive algorithm by terms of recursion as Haskell does not support loops. Perhaps if we can get loops, situation will improve, but then that wouldn't be functional style.
Could you give an example of a loop you find awkward in Haskell?
Well I want simple loop for(int i =0;i<10;++i)doSomething(i); in haskell that would be for begin end f | begin /= end = do {f begin ; for (begin+1) end f} | otherwise = return ()
I've often found that you can just define a control construct in Haskell when needed (e.g., some kind of loop).
I don't know how to do that. Greetings, Bane. _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

Perhaps something like for :: Int -> Int -> (Int -> IO ()) -> IO () for begin end f = sequence_ [ f i | i <- [begin..end] ] *Main> for 1 10 print 1 2 3 4 5 6 7 8 9 10 On 25/12/2005, at 9:35 PM, Branimir Maksimovic wrote:
From: Lennart Augustsson
To: Branimir Maksimovic CC: daniel.carrera@zmsl.com, Haskell-Cafe@haskell.org Subject: Re: [Haskell-cafe] Haskell vs OCaml Date: Sun, 25 Dec 2005 10:25:44 +0100 Branimir Maksimovic wrote:
I've found that Haskell is pretty good in implementing recursive algorithms. Problem cames when one want's to implement non recursive algorithm by terms of recursion as Haskell does not support loops. Perhaps if we can get loops, situation will improve, but then that wouldn't be functional style.
Could you give an example of a loop you find awkward in Haskell?
Well I want simple loop for(int i =0;i<10;++i)doSomething(i); in haskell that would be for begin end f | begin /= end = do {f begin ; for (begin+1) end f} | otherwise = return ()
I've often found that you can just define a control construct in Haskell when needed (e.g., some kind of loop).
I don't know how to do that.
Greetings, Bane.
_________________________________________________________________ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

From: Matt Collins
To: "Branimir Maksimovic" CC: Haskell-Cafe@haskell.org Subject: Re: [Haskell-cafe] Haskell vs OCaml Date: Sun, 25 Dec 2005 21:42:35 +1100 Perhaps something like
for :: Int -> Int -> (Int -> IO ()) -> IO () for begin end f = sequence_ [ f i | i <- [begin..end] ]
*Main> for 1 10 print 1 2 3 4 5 6 7 8 9 10
Great! what are constrains on [begin..end] could they be some type which supports (+) , but not Int. I need this cause perhaps there is possibility to impleemnt STL like algo's in Haskell and that would be even better then C++, cause Haskell has more powerfull parametric polimorfism and C++ badly needs lambda's. That's why STL is somewhat ugly, but lib tried to employ functional style programming over sequences and is not bad, though in C++ one has to make lot of auxiliary classes because of lack of lambda's. If I can make Iterator generic class and specialize for different containers that would be it. Last question is: Does creation of list of functions humpers performance? Greetings, Bane.
On 25/12/2005, at 9:35 PM, Branimir Maksimovic wrote:
From: Lennart Augustsson
To: Branimir Maksimovic CC: daniel.carrera@zmsl.com, Haskell-Cafe@haskell.org Subject: Re: [Haskell-cafe] Haskell vs OCaml Date: Sun, 25 Dec 2005 10:25:44 +0100 Branimir Maksimovic wrote:
I've found that Haskell is pretty good in implementing recursive algorithms. Problem cames when one want's to implement non recursive algorithm by terms of recursion as Haskell does not support loops. Perhaps if we can get loops, situation will improve, but then that wouldn't be functional style.
Could you give an example of a loop you find awkward in Haskell?
Well I want simple loop for(int i =0;i<10;++i)doSomething(i); in haskell that would be for begin end f | begin /= end = do {f begin ; for (begin+1) end f} | otherwise = return ()
I've often found that you can just define a control construct in Haskell when needed (e.g., some kind of loop).
I don't know how to do that.
Greetings, Bane.
_________________________________________________________________ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
_________________________________________________________________ FREE pop-up blocking with the new MSN Toolbar - get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/

Branimir Maksimovic wrote:
Great! what are constrains on [begin..end] could they be some type which supports (+) , but not Int. Anything in the Enum class (so it doesn't even have to support (+)). Many things are in the Enum class.
Last question is: Does creation of list of functions humpers performance? With optimization the list is usually never built.
-- Lennart

On 12/25/05, Branimir Maksimovic
From: Lennart Augustsson
To: Branimir Maksimovic CC: daniel.carrera@zmsl.com, Haskell-Cafe@haskell.org Subject: Re: [Haskell-cafe] Haskell vs OCaml Date: Sun, 25 Dec 2005 10:25:44 +0100 Branimir Maksimovic wrote:
I've found that Haskell is pretty good in implementing recursive algorithms. Problem cames when one want's to implement non recursive algorithm by terms of recursion as Haskell does not support loops. Perhaps if we can get loops, situation will improve, but then that wouldn't be functional style.
Could you give an example of a loop you find awkward in Haskell?
Well I want simple loop for(int i =0;i<10;++i)doSomething(i); in haskell that would be for begin end f | begin /= end = do {f begin ; for (begin+1) end f} | otherwise = return ()
Or just 'mapM_ doSomething [1..10]' (:
I've often found that you can just define a control construct in Haskell when needed (e.g., some kind of loop).
I don't know how to do that.
Greetings, Bane.
_________________________________________________________________ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Friendly, Lemmih

From: Lemmih
To: Branimir Maksimovic CC: lennart@augustsson.net, Haskell-Cafe@haskell.org Subject: Re: [Haskell-cafe] Haskell vs OCaml Date: Sun, 25 Dec 2005 11:43:56 +0100 On 12/25/05, Branimir Maksimovic
wrote: From: Lennart Augustsson
To: Branimir Maksimovic CC: daniel.carrera@zmsl.com, Haskell-Cafe@haskell.org Subject: Re: [Haskell-cafe] Haskell vs OCaml Date: Sun, 25 Dec 2005 10:25:44 +0100 Branimir Maksimovic wrote:
I've found that Haskell is pretty good in implementing recursive algorithms. Problem cames when one want's to implement non recursive algorithm by terms of recursion as Haskell does not support loops. Perhaps if we can get loops, situation will improve, but then that wouldn't be functional style.
Could you give an example of a loop you find awkward in Haskell?
Well I want simple loop for(int i =0;i<10;++i)doSomething(i); in haskell that would be for begin end f | begin /= end = do {f begin ; for (begin+1) end f} | otherwise = return ()
Or just 'mapM_ doSomething [1..10]' (:
Neet! However would it be more efficient for, say, 1 million iterations? Anyway I have to look for map functions. I'm learning step by step from tutorials :) Greetings, Bane.
I've often found that you can just define a control construct in Haskell when needed (e.g., some kind of loop).
I don't know how to do that.
Greetings, Bane.
_________________________________________________________________ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Friendly, Lemmih
_________________________________________________________________ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

On Sun, Dec 25, 2005 at 11:09:51AM +0000, Branimir Maksimovic wrote:
Or just 'mapM_ doSomething [1..10]' (:
Neet! However would it be more efficient for, say, 1 million iterations? Anyway I have to look for map functions. I'm learning step by step from tutorials :)
I remember I was impressed when I checked what GHC made of such code. No lists, no allocations, just a tight loop :-) BTW, in my library of small Haskell utilities I have for_ l f = mapM_ f l for l f = mapM f l and I use it like this for_ [1..10] $ \i -> do do something with i It's just because there's often more code in f than in l. When I don't have my handy little library, I use a more baroque syntax: (`mapM_` [1..10]) $ \i -> do do something with i Now that I think about it, this variant would be nicer: flip mapM_ [1..10] $ \i -> do do something with i Best regards Tomasz -- I am searching for a programmer who is good at least in some of [Haskell, ML, C++, Linux, FreeBSD, math] for work in Warsaw, Poland

Branimir Maksimovic wrote:
Well I want simple loop for(int i =0;i<10;++i)doSomething(i); in haskell that would be for begin end f | begin /= end = do {f begin ; for (begin+1) end f} | otherwise = return ()
How about: result = [ doSomething(i) | i <- [0..9] ] I guess it depends on what doSomething() does. Cheers, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/ I am not over-weight, I am under-tall. /

It would be very instructive to know the story behind LexiFi's decision to use OCAML for their implementation. The original work was done in Haskell and seemed to take good advantage of lazy evaluation. Does anybody know this story? http://www.lexifi.com/ http://www.lexifi.com/Downloads/MLFiPaper.pdf On Dec 23, 2005, at 7:35 PM, Daniel Carrera wrote:
Now that I sort of understand Haskell, I was hoping someone could give me an opinion on OCaml from a Haskell POV.
-------------------------------- David F. Place mailto:d@vidplace.com

I particularly like OCaml's provision of subtyping. As a member of the ML family, it's module system is also quite formidable. Of course the imperative constructs are also pretty convenient when you just want to be quirky. But I miss the monad do-notation.
participants (11)
-
Albert Lai
-
Branimir Maksimovic
-
Daniel Carrera
-
David F. Place
-
Glynn Clements
-
Hal Daume III
-
Joel Reymont
-
Lemmih
-
Lennart Augustsson
-
Matt Collins
-
Tomasz Zielonka