caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* practical functional programming
@ 2000-11-03 22:44 Chris Hecker
  2000-11-04 18:48 ` Chet Murthy
                   ` (3 more replies)
  0 siblings, 4 replies; 21+ messages in thread
From: Chris Hecker @ 2000-11-03 22:44 UTC (permalink / raw)
  To: caml-list


So, I've been reading some papers by Okasaki on functional data structures, and I've ordered his book.  I have some questions, and I don't mean these to be flame bait; they're honest questions from an imperative programmer trying to grok this functional thing.

First, let me say that I love the idea of higher order functions, currying, closures, variant types, pattern matching, gc, and the like.  I think I understand some of the power that comes with those techniques, and I'm eager to try them in a real sized project.

However, after reading Okasaki's papers about functional datastructures, I'm not sure I get why someone would go to all that trouble.  In other words, I can trivially write an O(1) queue using imperative languages (or imperative features of a funcional lanugage, like caml's queue.ml).  Okasaki goes to a _lot_ of trouble to implement an O(1) queue in a pure functional way, using all sorts of lazy optimizations and scheduling and whatnot.  He acheives O(1), but the constant is going to be rather large compared to shuffling a pointer/ref around in C/caml.

So, what does all this trouble buy you?  I vaguely understand how a purely functional language like Haskell might be more amenable to analysis and proof than C, but people jump through hoops to get that (read: IO monads in Haskell, Okasaki's datastructures).  Is it worth it?  Clearly the caml folks didn't think so because the standard library datastructures are destructively modifying.

I'm open minded, so I'm genuinely interested to know if the work of making something like a simple datastructure purely functional is more than an academic exercise, or if it pays back in real-sized production software.

Chris



^ permalink raw reply	[flat|nested] 21+ messages in thread
* Re: practical functional programming
@ 2000-11-06 23:10 Hao-yang Wang
  0 siblings, 0 replies; 21+ messages in thread
From: Hao-yang Wang @ 2000-11-06 23:10 UTC (permalink / raw)
  To: caml-list; +Cc: Chris Hecker

When you need to preserve the mutation history (or multi-history) of the 
data, Okasaki's data structures are useful. For other cases, I see 
nothing wrong in using mutable data structures.

>So, what does all this trouble buy you?  I vaguely understand how a purely 
>functional language like Haskell might be more amenable to analysis and 
>proof than C, but people jump through hoops to get that (read: IO monads 
>in Haskell, Okasaki's datastructures).  Is it worth it?  Clearly the caml 
>folks didn't think so because the standard library datastructures are 
>destructively modifying.

Haskell is a lazy language, with which we are supposed to ignore when (or 
whether) an expression is going to be evaluated, at least most of the 
time. As the result we have to give up all the side effects (i.e., I/O 
and destructive data updates), because we have no idea on the order in 
which these side effects occur. On the other hand, the ML family is 
strict.

I do not shy away from using side effects with o'caml. However, when I 
look back to the o'caml programs I wrote, I am always surprised in how 
pure they turned out to be: The side effects flock to a few places, 
usually at the top-most functions.

For a nice example on how the imperative features can help in writing a 
correct o'caml program, look at <http://caml.inria.fr/icfp99-contest/>.

Cheers,
Hao-yang Wang



^ permalink raw reply	[flat|nested] 21+ messages in thread
* Re: practical functional programming
@ 2000-11-06 23:24 Hao-yang Wang
  0 siblings, 0 replies; 21+ messages in thread
From: Hao-yang Wang @ 2000-11-06 23:24 UTC (permalink / raw)
  To: caml-list

>Haskell is a lazy language, with which we are supposed to ignore when (or 
>whether) an expression is going to be evaluated, at least most of the 
>time. As the result we have to give up all the side effects (i.e., I/O and 
>destructive data updates), because we have no idea on the order in which 
>these side effects occur. On the other hand, the ML family is strict.

People who complain that o'caml does not have a fixed evaluation order on 
function arguments should take a look at Haskell, things are much worse 
there. :-)

Hao-yang Wang



^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2000-11-13  8:16 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-11-03 22:44 practical functional programming Chris Hecker
2000-11-04 18:48 ` Chet Murthy
2000-11-05 14:25 ` John Max Skaller
2000-11-06 22:26   ` Michael Hicks
2000-11-06  6:55 ` Francisco Reyes
2000-11-06 13:16 ` Jean-Christophe Filliatre
2000-11-06 18:15   ` Chris Hecker
2000-11-07  7:54     ` Stephan Houben
2000-11-11 14:32       ` John Max Skaller
2000-11-12 13:17         ` Ken Wakita
2000-11-12 20:09           ` John Max Skaller
2000-11-13  0:19             ` Ken Wakita
2000-11-13  7:45         ` STARYNKEVITCH Basile
2000-11-07  9:06     ` Xavier Leroy
2000-11-07 10:13       ` Chris Hecker
2000-11-09 10:56         ` Stephan Houben
2000-11-09 21:56           ` Chris Hecker
2000-11-07 18:05     ` Thorsten Ohl
2000-11-07 19:19     ` Marcin 'Qrczak' Kowalczyk
2000-11-06 23:10 Hao-yang Wang
2000-11-06 23:24 Hao-yang Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).