Haskell vs OCaml

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
22 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Haskell vs OCaml

Daniel Carrera-2
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.
    /
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Haskell vs OCaml

Hal Daume III-2
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                                   | [hidden email]
 "Arrest this man, he talks in maths."           | www.isi.edu/~hdaume

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Haskell vs OCaml

Tomasz Zielonka
In reply to this post by Daniel Carrera-2
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
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Haskell vs OCaml

Joel Reymont
In reply to this post by Hal Daume III-2
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.

--
http://wagerlabs.com/





_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Haskell vs OCaml

David Place
In reply to this post by Daniel Carrera-2
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:[hidden email]

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Haskell vs OCaml

Daniel Carrera-2
In reply to this post by Tomasz Zielonka
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.
    /
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Haskell vs OCaml

Daniel Carrera-2
In reply to this post by Hal Daume III-2
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.
    /
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Haskell vs OCaml

Donn Cave-2
In reply to this post by Daniel Carrera-2
Quoth Tomasz Zielonka <[hidden email]>:
...
| There are many differences (Haskell on the left):

Might also mention foreign (C) function interface (FFI.)  ocaml's is
I would say average, but ghc's is outstanding, really a different
level of support altogether.

With regard to the syntax - aside from esthetic questions or awkward
notations, there are some practical problems with Objective CAML's
common syntax, having to do with optional block delimiters and ";"
as a statement concatenator.  Sometimes you need to add what seems
like gratuitous delimiters to compensate for the kind of unintuitive
interpretation.  There's a revised syntax that eliminates this problem
among other things, but little apparent interest from the community
(which figures - they wouldn't be using Objective CAML if this was
a high priority for them.)

ocaml is nice work, though - very portable compiler that produces
native code, and that has helped promote FP in general even if the
language isn't all that rigorously functional (mutable strings!?)
It seems like it might do very well if it were adopted by basically
a new community that would insist on the revised syntax and would
make serious use of the OO side of the language, which is kind of
interesting.

        Donn Cave, [hidden email]
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Haskell vs OCaml

Daniel Carrera-2
In reply to this post by Tomasz Zielonka
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.
    /
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Haskell vs OCaml

Tomasz Zielonka
In reply to this post by Daniel Carrera-2
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
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Haskell vs OCaml

Branimir Maksimovic-2
In reply to this post by Daniel Carrera-2



>From: Daniel Carrera <[hidden email]>
>To: [hidden email]
>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/

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Haskell vs OCaml

Lennart Augustsson
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
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Haskell vs OCaml

Branimir Maksimovic-2



>From: Lennart Augustsson <[hidden email]>
>To: Branimir Maksimovic <[hidden email]>
>CC: [hidden email], [hidden email]
>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
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Haskell vs OCaml

Matt Collins
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 <[hidden email]>
>> To: Branimir Maksimovic <[hidden email]>
>> CC: [hidden email], [hidden email]
>> 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
> [hidden email]
> http://www.haskell.org/mailman/listinfo/haskell-cafe

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Haskell vs OCaml

Lemmih
In reply to this post by Branimir Maksimovic-2
On 12/25/05, Branimir Maksimovic <[hidden email]> wrote:

>
>
>
> >From: Lennart Augustsson <[hidden email]>
> >To: Branimir Maksimovic <[hidden email]>
> >CC: [hidden email], [hidden email]
> >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
> [hidden email]
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


--
Friendly,
  Lemmih
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Haskell vs OCaml

Branimir Maksimovic-2
In reply to this post by Matt Collins



>From: Matt Collins <[hidden email]>
>To: "Branimir Maksimovic" <[hidden email]>
>CC: [hidden email]
>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 <[hidden email]>
>>>To: Branimir Maksimovic <[hidden email]>
>>>CC: [hidden email], [hidden email]
>>>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
>>[hidden email]
>>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/

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Haskell vs OCaml

Branimir Maksimovic-2
In reply to this post by Lemmih



>From: Lemmih <[hidden email]>
>To: Branimir Maksimovic <[hidden email]>
>CC: [hidden email], [hidden email]
>Subject: Re: [Haskell-cafe] Haskell vs OCaml
>Date: Sun, 25 Dec 2005 11:43:56 +0100
>
>On 12/25/05, Branimir Maksimovic <[hidden email]> wrote:
> >
> >
> >
> > >From: Lennart Augustsson <[hidden email]>
> > >To: Branimir Maksimovic <[hidden email]>
> > >CC: [hidden email], [hidden email]
> > >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
> > [hidden email]
> > 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/

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Haskell vs OCaml

Tomasz Zielonka
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
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Haskell vs OCaml

Daniel Carrera-2
In reply to this post by Branimir Maksimovic-2
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.
    /
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Haskell vs OCaml

Glynn Clements
In reply to this post by Branimir Maksimovic-2

Branimir Maksimovic wrote:

> >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);

        mapM_ doSomething [0..9]

--
Glynn Clements <[hidden email]>
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
12