Posts: 5,143
Joined: 2002.04
Post: #16
Quote:Originally posted by Zoldar256
But I never saw anybody say, "Hey here's my FPS written in SML/Haskell/Rex!"

Quake Haskell?

(Quite possibly the worst example of functional programming ever, but hey!)
Quote this message in a reply
Post: #17
Quote:Originally posted by Zoldar256
So I suppose closures are kinda like functions that represent the partial evaluation of another function.
Sorry about my bad explanation, hope you get the idea tho.

That does help a lot, thanks. With this thread and this online book, it's all starting to come together. Any idea why they are called "closures"?
Quote this message in a reply
Post: #18
Free Orielly books.... Mmmmmmmmmmmmmmmmmmmm

Quote:Any idea why they are called "closures"?
I have no idea. I'll check a book on programming language theory as soon as I get back from vacation.

Only relation I can think of is: "Closing" something, like a transaction, usually means completing it from some partially completed state. So thus a Closure is what completes a partially completed function?
Quote this message in a reply
Posts: 304
Joined: 2002.04
Post: #19
Quote:Originally posted by M.J.
If we're in a MVC world, functional languages seem to me to fit the model part, but not so much the controller part where I seem to spend most of my time.

Interesting. I think we all spend too much time writing our controller objects. Most of the code is more tedious and rote than creative. It should be more automated somehow IMO. Ive heard rumors that this is much improved in Panther - can anyone confirm and possibly explain?
Quote this message in a reply
Post: #20
I have been using OCaml in industry for the last couple of years. It is an excellent language and I have not yet had a single serious problem with it. Like any language, it does have some caveats but these are few and far between compared to languages like C++.

Although I have many more years of experience with C++, I am finding that I can already develop software in OCaml around 10x faster than I could in C++. OCaml makes incremental development much easier, primarily because functional programming leads to much cleaner separation of code and much less code duplication, and iterative improvements (even fundamental ones) require far fewer alterations in OCaml than they do in C++.

Performance is excellent. The biggest application I have written (25kLOC of OCaml) is 5x faster than the C++ version that took me a lot longer to develop and required several times as much code.

The OCaml community are also very helpful, and the OCaml mailing lists typically get any questions answered quickly and accurately. In an attempt to give back to the community, I am publishing lots of open-source OCaml programs:


I have written some web pages explaining the benefits of the OCaml programming language:


and I have written a book on OCaml (aimed at computational scientists):


The first chapter is freely available as PDF and HTML and it should give anyone a decent introduction to the language.

I am considering writing a book on OCaml for Games Programming.

Quote this message in a reply
Post: #21
M.J. Wrote:If you only only want to count lines of code, I can do that in one line in C++:

transform(array.begin(), array.end(), array.begin(), bind2nd(plus<int>(), 1));

The OCaml equivalent to that one line of C++ is actually:

map ((+) 1)

The genericity of C++'s "transform" (it can be applied to any data structure whereas OCaml must use a "map" function for a specific data structure, e.g. Lisp.map or Array.map) is traded for more pedantic static type checker and the ability to pass arbitrary functions (including closures) without having to use magic like bind2nd.

Quote:Seriously though, this isn't a lines-of-code contest. My experience with functional languages is minimal at best (very basic experimentation with Haskell), but I can see many advantages. As a "math" guy the declarative nature of functional languages really appeals to me. I'd love to implement some real-world problem in a functional language to see for myself the advantages/disadvantages over C++ (the procedural language I work in most often), but I don't think I can convince the guys at work to go for that.

It only took me 6 months of working with OCaml before I could write the majority of my software much more easily in OCaml than in C++. Now I consult for other people on OCaml. I'd estimate that development in OCaml (for numerical, visualisation and GUI software in my case) is 10x faster than in C++.

Quote:And here's why... when I think about it, very little of my time is spent defining algorithms, or even debugging algorithms. When I think about this, the benefits of a function language start to fade. How is a functional language going to help me interface with a SQL database better?

The more expressive type systems of languages like OCaml allow you to write APIs that convey much more information. What was documentation in C++ often becomes machine-verified specification in OCaml.

Quote:How is it going to help me create a GUI?

I find that programs are often best written with an imperative front-end (GUI) and a functional back-end. Most functional languages (including OCaml) support imperative programming as well. The advantages of the functional aspects are things like the ease of specifying callback functions.

Quote:How is it going to help me parse text files better?

That's easy - the ML family of languages (including OCaml) were specifically designed for writing compilers and interpreters. They come with very powerful lexer and parser generators which require much less code than C++ parsers, are much better statically checked and vastly easier and quicker to develop.
Quote this message in a reply
Post: #22
M.J. Wrote:That does help a lot, thanks. With this thread and this online book, it's all starting to come together.

You may also like to read the freely available first chapter of my book, OCaml for Scientists.

Quote:Any idea why they are called "closures"?

They are "closed off from their environment". This means that the definition of a local closure can capture environment such as local variables. This makes garbage collection essential as local variables can outlive the function they are defined in if they are captured by a closure with is returned in the result of the function.

Quote this message in a reply
Posts: 869
Joined: 2003.01
Post: #23
Just a few general observations:

IMO, it is a good idea to experiment with as many programming languages as you have time for. Each language brings in new ideas that are favoured by the implementation, and often the ideas carry to other languages and improve your overall programming. Also, you should choose that programming language that applies best to your problem at hand.

On the other hand, doing things in a well established language has the advantages of a large community and well supported dev tools.

I believe every language has its place, and that functional languages are not particularly well suited to games, where it very often comes down to doing data shuffling close to the hardware. Not that I don't beat my head on the table from time to time because of coding in C/C++, it's just how I feel about it.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  checkers code written in OCAML? ab44045 1 3,366 Jun 5, 2005 04:55 AM
Last Post: socksy