anyone using haskell?

22b3033832c5c699c856814b0cf80cb1
0
bladder 101 Oct 17, 2006 at 11:24

Hey guys,

I recently started learning the haskell programming language. It has support for the likes of opengl and win32 and all the necessary basics for developing graphical applicaitons. I was wondering if anyone has used haskell for anything significant over here. How was the experience, what are some obvious advantages (or disadvantages) you realized as opposed to application development in c/c++ or c# or whatever?

I’m loving this language so far. It’s so… different then what I’m used to. They should really add this kind of stuff to computer science courses.

I wrote a blog post here with a whole buch of links to how I got started and various tutorials and all if anyone is interested.

So, comments?

37 Replies

Please log in or register to post a reply.

6aa952514ff4e5439df1e9e6d337b864
0
roel 101 Oct 17, 2006 at 15:52

I had to use it for a course, probably to learn that there are more languages other than the imperative ones. We had to write a kind of Basic interpreter with it. Maybe I’m too conservative or maybe I have troubles to switch to things I’m not used with, but I never used it again. The programs you can create with it are sometimes beautiful though.

Regarding your blog and C# 3.0; I’m really looking forward for the lambda expressions (iirc). Seems quite useful to me.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Oct 17, 2006 at 18:31

@bladder

I’m loving this language so far. It’s so… different then what I’m used to. They should really add this kind of stuff to computer science courses.

I don’t know when/where you took computer science, but at my school functional programming has been a major part of the cirriculum (we haven’t used Haskell, but LISP and ML for sure). ;)

6f0a333c785da81d479a0f58c2ccb203
0
monjardin 102 Oct 17, 2006 at 18:44

Here is a good introductory article for those that are unaware of functional programming: Functional Programming For The Rest of Us

I’ve been considering trying out Haskell as well. The closest I’ve come to functional programming has been with Lua, but its too easy to cheat. Haskell gives you no such option!

I still don’t have a grasp on monads yet. Maybe then I’ll give Haskell a shot.

Also, I never heard of functional languages while getting my electrical engineering degree. :(

22b3033832c5c699c856814b0cf80cb1
0
bladder 101 Oct 17, 2006 at 19:16

well functional programming was not a part of my curriculum at all. There was one class that gave us a few intro lessons to lisp (our AI course), but the way it was taught in those 3-4 periods made it seem insignificant and completely useless. And it wasn’t actually “taught” as in how they tech OO/procedural concepts, it was just a “oh and by the way you can do this with this language”. Actually, it was so horribly taught that I don’t think those classes we had on it had anything to do with AI even though it was part of the AI course… And don’t even get me started with my AI course, it was the course I was looking most forward to in my final semester and turned out to be the biggest dissapointment ;)… but that’s quite OT so bleh…

496dc55447c4e329e8ce8736298e51e0
0
Jack9 101 Oct 17, 2006 at 19:27

I am using Erlang serverside, which has been about 10 times more effective than using C (in the past) or even Python for the short time I tried Python serverside.

6f0a333c785da81d479a0f58c2ccb203
0
monjardin 102 Oct 17, 2006 at 21:31

Multi-threading does seem to be the biggest benefit of functional languages. The functions have no side-effects, so threads can be created be the compiler as it sees fit. So, it makes sense that they would be great for server code.

99f6aeec9715bb034bba93ba2a7eb360
0
Nick 102 Oct 17, 2006 at 21:53

I personally think it sucks to be limited to recursion for loops.

Sure it can be helpful to have some functional concepts in a programming language, but forcing everything in that paradigm makes some simple things needlessly complicated. If you’re a mathematician and you’re only writing small applications, it can be great, but for anything really serious it quickly becomes a pain. The claims about needing less code are true, but you need just as long or longer to write it down…

I love C++ because it’s multi-paradigm. For nearly every problem there’s an elegant solution. This freedom brings its own complexity but once that’s mastered I see little reason to look at other languages except for very specific situations. Like my professor used to say: “I’m teaching you Haskell and Prolog to make you better C++ programmers”.

6f0a333c785da81d479a0f58c2ccb203
0
monjardin 102 Oct 18, 2006 at 02:38

That quote from your professor is my primary interest in the subject. I found it to be true already. ;)

22b3033832c5c699c856814b0cf80cb1
0
bladder 101 Oct 19, 2006 at 13:02

so no one here is really use it in the same sence as c++ then?

If you’re a mathematician and you’re only writing small applications, it can be great, but for anything really serious it quickly becomes a pain.

Hmm, that’s what I’m thinking so far. Though I can’t really argue on this because of my lack of experience in the functional domain, but I’m looking into how true this actually is. I’ve heard a lot about erlang for server side development. There’s an article here on devmaster actually: http://www.devmaster.net/articles/mmo-scalable-server

I love C++ because it’s multi-paradigm. For nearly every problem there’s an elegant solution. This freedom brings its own complexity but once that’s mastered I see little reason to look at other languages except for very specific situations.

Indeed, c++ really is a beauty in that regard. Though that’s also one of it’s biggest “pitfalls” in my opinions - a “full of adventure and surprise” pitfiall ;)

4851117d61425bafb6c034e0f595d517
0
DrunkenCoder 101 Oct 19, 2006 at 14:47

Just for kicks, when you’ve done some haskell go back and look at that nifty template facility C++ got.

You’ll be asthonised when you realize that you got a complete functional compiletime language built into your C++ compiler ;)
Doing work in haskell will enhance your ability to create complex template meta programs a great deal.

22b3033832c5c699c856814b0cf80cb1
0
bladder 101 Oct 19, 2006 at 17:41

yeah but using “raw” templates to get meta-programming functionality is not a walk in the park. But you are right, the light that is boost.lamda and boost.mpl do shine brighter after dabbeling in the functional world.

complete functional compiletime language built into your C++ compiler

That’s a bit of an exageration :huh:?

1dc7eb0d0fe271e2e595cf1215dc670f
0
snk_kid 101 Oct 21, 2006 at 10:55

@bladder

I’m loving this language so far. It’s so… different then what I’m used to. They should really add this kind of stuff to computer science courses.

Actually they do it just depends on which university and how good that university is.
@monjardin

I still don’t have a grasp on monads yet. Maybe then I’ll give Haskell a shot.

One of the most comprehensive resources on monads is All About Monads and Philip Wadler’s papers (the guy who brought monads to haskell).
@Nick

I personally think it sucks to be limited to recursion for loops.

:blink: i have to say your comment is quite odd, this just sounds like an ill-informed and inexperienced opinion. Actually it’s common for someone to say this who does not have much experience with recurision or just doesn’t naturally think recursively. If you had any idea you would know it’s quite the opposite.

if you’re not familliar with the concepts of Accumulators, recursive operators (patterns of recursion such as Catamorphisms), and languages which foster writing recursive functions (in which with C++ this is not the case) then you do not really have a place to make such comments.

I suggest you read a book like Structure and Interpretation of Computer Programs to get a better understanding of the subject.
@Nick

Sure it can be helpful to have some functional concepts in a programming language, but forcing everything in that paradigm makes some simple things needlessly complicated. If you’re a mathematician and you’re only writing small applications, it can be great, but for anything really serious it quickly becomes a pain. The claims about needing less code are true, but you need just as long or longer to write it down…

Exactly what are you basing your claims on? quite clearly this cannot be based on any comprehensive (personal) experience because of what you said above.

I can tell you for one thing there are many “serious” and significant applications which have and still are written in a number of functional programming languages so do not make assumptions and come out with rubbish like that.
@Nick

I love C++ because it’s multi-paradigm. For nearly every problem there’s an elegant solution. This freedom brings its own complexity but once that’s mastered I see little reason to look at other languages except for very specific situations. Like my professor used to say: “I’m teaching you Haskell and Prolog to make you better C++ programmers”.

:blink: Well now that just says it all doesn’t it…

22b3033832c5c699c856814b0cf80cb1
0
bladder 101 Oct 21, 2006 at 16:07

hey, same snk_kid from gamedev.net? I actually got started with haskell through the links in your sig on gdnet (if you’re the same)… :huh:

i have to say your comment is quite odd, this just sounds like an ill-informed and inexperienced opinion. Actually it’s common for someone to say this who does not have much experience with recurision or just doesn’t naturally think recursively. If you had any idea you would know it’s quite the opposite.

I have to agree with snk_kid on this, i’ve been “learning” haskell for about a week now (spend more or less my entire day on it), and recursion is getting much more natural. At the beginning I was weirded out by the fact that there were no loops as well, but it turns out that it makes more sense without them. You’ll have to spend a bit more time in a heskell like environment before things start to click.

F7a4a748ecf664f189bb704a660b3573
0
anubis 101 Oct 29, 2006 at 18:17

I learned Haskell in university and used it on and off from there on. It sure is a beatiful language allthough I generally am more in favor of lisp, since it is a multi paradigm language. Well… lisp by definition will be able to support close to any language feature you can think of. Sort of a local optimum in computer languages i guess.

We use Haskell in university for an automated theorem proover tool, that we produce. For that kind of work functional is the only way to go. I think for things that are less heavy on the algorithmic side and involve more “library calling” I wouldn’t want to use Haskell though.

As for the loops… One great thing about functional programming is that you can look at functions as idioms. So if you miss loops, just write a function that imitates a while loop and everything is fine. Of course Lisp with macros is even better that respect.

Comparing fucntional to oop I pondered about what concept is the more general for a while and which could be expressed better in the terms of the other. I think objects could be easily expressed in functional languages. In essence an objekt is a functional closure over the objects members, that can be passed a method name. Of course that wouldn’t include inheritance but that’s beside the point here.

A book I can reccomond on the topic is The Art Of The Meta Object Protocol, by Kiczales, Gregor, Jim des Rivieres, and Daniel G. Bobrow.

bladder :

from your blog :

“Haskell is a programming language, just like c++ or c# is… however, it is based on completely different concepts that are simply just different then what the average computer science student is used to.”

Well… C# is moving into a direction where they integrate functional concepts pretty extensively. C# now has functional closeures and anonymous methods i.e. lambda expressions, which is half the way. C3.0 is going to add type inference and real lambda expressions to that which is really nice. I tend to like this approach, because it’s good to make many programming paradigms available.

99f6aeec9715bb034bba93ba2a7eb360
0
Nick 102 Oct 30, 2006 at 00:10

@snk_kid

:blink: i have to say your comment is quite odd, this just sounds like an ill-informed and inexperienced opinion. Actually it’s common for someone to say this who does not have much experience with recurision or just doesn’t naturally think recursively. If you had any idea you would know it’s quite the opposite.

Could you add some arguments? Now you’re just offensive.

Seriously, being limited to recursion is silly. For some really simple things in an imperative language it takes mind bending complexity to do it in a purely functional language. Don’t forget that computers are imperative. When I’m writing C++, I already see the assembly code before me. With a functional language, there’s absolutely no guarantee that what I see is what will be executed. Writing high performance functional applications, like games, is a nightmare.

if you’re not familliar with the concepts of Accumulators, recursive operators (patterns of recursion such as Catamorphisms), and languages which foster writing recursive functions (in which with C++ this is not the case) then you do not really have a place to make such comments.

Again you forgot to add real arguments.

I suggest you read a book like Structure and Interpretation of Computer Programs to get a better understanding of the subject.

Again.

Exactly what are you basing your claims on? quite clearly this cannot be based on any comprehensive (personal) experience because of what you said above.

Again.

I can tell you for one thing there are many “serious” and significant applications which have and still are written in a number of functional programming languages so do not make assumptions and come out with rubbish like that.

Again you’re getting personal. Name some high performance applications for me please.

:blink: Well now that just says it all doesn’t it…

Actually the professor has decades of experience with functional languages. Claiming that teaching us functional languages will make us better C++ programmers is based on that experience. He went beyond functional languages and realized that it’s not important to teach a language like Haskell, but to teach a new paradigm. I can now use both functional and logical paradigms, together with imperative and object-oriented paradigms, in multi-paradigm languages like C++ and C#. It has taught me to use the right tool for the right job. I’m tackling problems which a couple years ago would have taken me more code for a less elegant solution.

Realizing the intrinsic limitations of functional languages is fundamental. They did not make a breakthrough on their own, nor will they ever. Multi-paradigm languages are far more popular, for good reason.

In the end, programming languages (and their compilers) are nothing more than tools to write assembly code. A ‘perfect’ language is worthless if it’s not practical. Remember that.

496dc55447c4e329e8ce8736298e51e0
0
Jack9 101 Oct 30, 2006 at 17:56

Name some high performance applications for me please.

Erlang:
Wings3D
Yaws

For a couple years I thought that Erlang was the only practical FPL.

Lisp:
Yahoo’s Online Shopping Cart
(in the late 90’s, although I cannot speak to their current state on any given domain)

It’s unlikely that these are the only examples, but these are the ones that I have seen the sourcecode for. You can hear of the woes of trying to explain how NASA’s software is almost all FP from JPL and NASA engineers, but NASA doesn’t want sourcecode released…ever. There are some scattered Erlang voice/data programs from NASA on the web. In the 80’s, the British metropolitan phone systems were controlled by Ericsson (Erlang) phone routing software (some still is). I’m afraid I’ve long since forgotten the obscure names to the Traffic Control Software in Erlang that I’ve played with or the phone control software.

Seriously, being limited to recursion is silly.

Please do not argue your professor’s views by proxy, as he is not here to correct your memory or reasoning. As it stands, this statement is false on it’s face. You provide no reason it is silly, other than you don’t accept it for some esoteric personal reasons. When you can actually write something in an FP again (since you’ve clearly drawn upon your vague memories of languages you had been told were impractical), you might learn some of your biases are unfounded, while others may be justified.

Actually the professor has decades of experience with functional languages.

After a couple years in the trenches, it has become very clear to me that I cannot trust everything I have been taught. When I go back to school to learn a new language there is an Ivory tower. A common problem among academia, wherein an instructor spends enough time teaching the basics, that they believe they are an expert in what’s practical. Again, while I have no reason to doubt you have been told certain things about FP, when my experience contradicts your claims, reality wins. This means you continue to believe what you like until you take the time to find out for yourself, based on differing opinions from programmers like yourself.

Ex:
I’ve tried it, and AJAX is silly. AJAX is XMLHttpRequest Object and what you can do with it…but it’s not clever enough for PHBs, so they called it AJAX.

He went beyond functional languages

This is a cute catchphrase. Going beyond FP would be to program at a lower level, as FPs are commoditized wrappers for common imperative objects and actions. A lot of people really hate the syntax. I personally like Erlang and Lisp, hate Haskell (sorry OP :p)

functional and logical paradigms

Functional and Imperative. Both of them are logical.

Hope you try out some FPL again and come back with some real problems that FP can’t solve. It’s been a long time since I’ve seen a serious FP challenge. Pwning CODERS with actual examples is a lot more fun than posturing, since you get taken more seriously. More importantly, try a more appropriate forum (like comp.lang.functional) for stating that FP is useless when people use it every day. It’s obvious that very few people use it here and a great many don’t even use C yet.

99f6aeec9715bb034bba93ba2a7eb360
0
Nick 102 Oct 31, 2006 at 04:01

@Jack9

Erlang:
Wings3D
Yaws

Never heard of them. :whistle:

By the way, with high-performance I actually meant performance critical. I’d love to see an AAA game or something like a video codec in a functional language…

It’s unlikely that these are the only examples, but these are the ones that I have seen the sourcecode for. You can hear of the woes of trying to explain how NASA’s software is almost all FP from JPL and NASA engineers, but NASA doesn’t want sourcecode released…ever. There are some scattered Erlang voice/data programs from NASA on the web. In the 80’s, the British metropolitan phone systems were controlled by Ericsson (Erlang) phone routing software (some still is). I’m afraid I’ve long since forgotten the obscure names to the Traffic Control Software in Erlang that I’ve played with or the phone control software.

As far as I know the primary goal of such software is correctness. I’m sure NASA doesn’t care if it’s a few time slower than an optimized imperative program, as long as it keeps the Space Shuttle from crashing into the earth. For these applications I’m convinced that purely functional languages have great benefits. It’s excellent for control.

I tried a couple times to write a high-performance application in Haskell, but I just didn’t get what I expected. It’s just far less suited for number crunching. I’m aware that the compiler has a lot to do with it, but that’s a worthless excuse in practice. It’s also likely that I could have gotten higher performance if I rewrote some things differently, but if it requires a PhD in math to get a language to do exactly what I want then I don’t want to bother with it. Sometimes it’s even easier to just write the assembly code. At that point using these languages is not worth it.

This is a site about game development, and I just don’t think functional languages are very useful there. But don’t get me wrong, I still find them very interesting and I know they are useful for certain classes of applications. They just have their limitations. In a multi-paradigm language I get the best of both worlds and I’m not limited.

Please do not argue your professor’s views by proxy, as he is not here to correct your memory or reasoning. As it stands, this statement is false on it’s face. You provide no reason it is silly, other than you don’t accept it for some esoteric personal reasons. When you can actually write something in an FP again (since you’ve clearly drawn upon your vague memories of languages you had been told were impractical), you might learn some of your biases are unfounded, while others may be justified.

If I want a loop, I want a loop. In my opinion, recursion is more complicated than a loop. That’s my reason why I think it’s silly. These languages are so mathematically sound, that they are harder to use in practice. Loops are still simple, but there are other things that are almost a no-brainer in an imperative language but needlessly complicated in a functional language.

After a couple years in the trenches, it has become very clear to me that I cannot trust everything I have been taught. When I go back to school to learn a new language there is an Ivory tower. A common problem among academia, wherein an instructor spends enough time teaching the basics, that they believe they are an expert in what’s practical. Again, while I have no reason to doubt you have been told certain things about FP, when my experience contradicts your claims, reality wins. This means you continue to believe what you like until you take the time to find out for yourself, based on differing opinions from programmers like yourself.

I am very well aware that professors do now always know how to put their theory into practice. But this professor actually realized that functional languages are too academic to ever become really popular.

Hope you try out some FPL again and come back with some real problems that FP can’t solve. It’s been a long time since I’ve seen a serious FP challenge. Pwning CODERS with actual examples is a lot more fun than posturing, since you get taken more seriously. More importantly, try a more appropriate forum (like comp.lang.functional) for stating that FP is useless when people use it every day. It’s obvious that very few people use it here and a great many don’t even use C yet.

Where did I claim that functional programming can’t solve certain problems? Where did I claim that functional programming is useless?

All I’m saying is that they can be limiting in practice for certain applications.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Oct 31, 2006 at 05:00

@Nick

In a multi-paradigm language I get the best of both worlds and I’m not limited.

I’d just like to point out that multi-paradigm languages often don’t let you use functions as first-class values, like passing a function as parameter to another one, declaring a local function and returning it, and so on. This is one of the main features of functional languages and it can be very handy. In C++ you can emulate some of this with function pointers but it’s nasty; as far as I know Java has no support for this sort of thing at all. However, the next version of C# is supposed to have lambda expressions, so we’ll see how that goes.

If I want a loop, I want a loop. In my opinion, recursion is more complicated than a loop. That’s my reason why I think it’s silly. These languages are so mathematically sound, that they are harder to use in practice.

I find certain algorithms easier to think about in recursive terms. For instance, binary tree operations like searching and inserting, quicksort, recursive descent parsing of grammars, and so forth are easier to think about and more elegant in a recursive framework. Sure, in C++ we can write these recursively if we want to. But we don’t want to, because recursion is inefficient, so we rewrite them iteratively and they become harder to understand. In a functional language we can write them recursively, and if we make them tail-recursive they are almost as efficient as an imperative, iterative implementation. (As far as I know, no C++ or Java compiler optimizes tail recursion, but correct me if I’m wrong.)

Additionally, I find recursive reasoning generally easier to follow than iterative reasoning. Both are essentially equivalent, but I find the idea of a base case and then a recursive case that reduces the problem to a simpler one easier to think about than a loop invariant with initialization, maintenance, and termination arguments. If I’m trying to convince myself that something I’ve written is correct, it’s better if it’s recursive. This wasn’t always the case. When I first encountered functional languages as a first year university student, I would have agreed with you that recursion was more complicated than a loop. It took some time before I learned how to think about recursion, but now it seems just as natural as a loop to me.

Of course, everything I’m saying here just applies to me and not necessarily to anyone else. If you don’t like recursion, that’s fine; but I hope you can see how people can have different perspectives on the matter.

…there are other things that are almost a no-brainer in an imperative language but needlessly complicated in a functional language.

Could you give an example? I think it would help the discussion if we had something concrete to point to rather than speaking in generalities all the time.

This is a site about game development, and I just don’t think functional languages are very useful there.

Realistically, I’m inclined to agree. But that doesn’t mean we can’t discuss them. ;)

89cc6724a9068a969bcadadfea63fbfe
0
The_Grey_Beast 101 Oct 31, 2006 at 13:36

Just remember that “math” definitions and symbols are not the BEST. That is, recursion (math-oriented) is not necessarily the BEST. I know some of you might consider me a loop-lover, but please think about math first – it’s not the super-ultra-universal easiest-to-read and perfect language. I find intuitive examples much easier to follow

Next, functional programs depend mainly on compiler. Compilers do most of the job. However they STILL rely on us, else we wouldn’t have programmers :) This means, he has to “guess” what we wanted to accomplish, thus never really knowing the task at hand. On the other hand, if we use imperative languages, we can easily translate it with our minds directly in an “execution” oriented thing, i.e we know almost anything about the result – thus we can write better code in this respect.

Math-lovers (this does not mean math-logic, but rather math-language): use functional languages

Logic-lovers (sorry if “logic” is not the correct term, I’m not native english): use imperative languages

ps: by “logic” I mean.. well example:

1) Aha, it computes 5+1
2) then is sees if it’s > 5
3) then it jumps somewhere
4) then, based on that new variable, adds 1
5) then….

again sorry if logic is not an appropiate term.

In my opinion (just my opinion, please don’t offense), math-language (not logic, just language) sucks! A good example that requires a “special” symbol in math is “Sigma” (for sums, you know).. it represents a loop.. it needs that, because it doesn’t want to process it as loops. Math-language sucks. It’s too :wacko:

Other funny things in math: if and only if, instead of plain if, etc..

math-logic is same for both imperative and functional languages, however imperative extend this (logic operators, weird tricks, etc). Math is abstract, I know, but the language in my opinion is :wacko:.. too confusing

please do not regard this as an offense. it was only my opinion

820ce9018b365a6aeba6e23847f17eda
0
geon 101 Oct 31, 2006 at 14:12

Jack9:

“Hope you try out some FPL again and come back with some real problems that FP can’t solve.”

I actually haven’t been programming in functional laguages, but Ihave been studying Haskell and Lisp, trying to understand them.

I somewhat hit a wall when I tried to implement the first algorithm I thought about as suitable for FP: Othello/Reversi boardgame AI. I have done it in C earlier, so I thought it would be a good way to try out the languages.

But as soon as I started looking at the problem, I realized I had absolutely NO IDEA how to represent the board and pieces. Of course, I should probably just ignore that by abstracting it with a nice set of functions, but still… I need to do it sooner or later, and it sets my brain spinning.

How could it be done in an elegant way?

22b3033832c5c699c856814b0cf80cb1
0
bladder 101 Oct 31, 2006 at 15:19

From my understanding so far, when you get to anything to do with representing state changes in a functional language, then if the functional language is pure, you’re stuck… or so I thought anyway. At the end of the day you end up doing imperative like programming within a functional programming language for handling state. If it’s a pure functional language (ala haskell), then there are ways to go about maintining referential transparency by using something called a monad (i’m still learning so, take the words I use with a grain of salt ;)). In non-pure FPs they allow the mixture of real imperative style constructs but with a loss of referential transparency.

snk_kid (who’s posted above) gave me some info/links when I wrote a blog entry about this “issue”. Mind you, it’s haskell specific (i think - as I’m still quite knew to the functional world). But one link in particular tackled this problem head on.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Oct 31, 2006 at 16:54

@bladder

From my understanding so far, when you get to anything to do with representing state changes in a functional language, then if the functional language is pure, you’re stuck… or so I thought anyway. At the end of the day you end up doing imperative like programming within a functional programming language for handling state.

Another way to accomplish this is to encapsulate your state in some data structure, which you pass into each function, and let each function return a new state (along with possibly other values). For instance I had an assignment to write a recursive descent parser in ML this way. Every parser function had a parameter that would take the list of tokens and then would return a pair consisting of the parse tree and the list of remaining tokens after that function had done its job. No pseudo-imperative programming was needed and it came out rather elegantly.

But, in general, representation of state changes that way is rather inefficient, since you might have to allocate a bunch of memory and copy the entire old state in order to change one little piece (unless the compiler can optimize it away, as it frequently can for simple structures like lists and trees). So this another good argument for multi-paradigm languages. I haven’t used Lisp extensively and Haskell not at all, but I’ve played around with ML quite a bit - anyone else used it? I consider ML somewhat multi-paradigm since while it’s clearly functional at heart it also allows imperative programming without too much nasty syntax, and also allows the definition of complex types that you could potentially use to create ‘classes’ and ‘objects’ (though I’ve never actually tried doing this).
@geon

But as soon as I started looking at the problem, I realized I had absolutely NO IDEA how to represent the board and pieces.

I would probably use a list of (x,y) pairs for each player, where each element of the list represented the location of one piece on the board. Then you can combine two such lists into another pair to make the complete state of both players’ pieces. Simple, yet effective…

99f6aeec9715bb034bba93ba2a7eb360
0
Nick 102 Nov 01, 2006 at 00:46

@Reedbeta

If you don’t like recursion, that’s fine; but I hope you can see how people can have different perspectives on the matter.

I do like recursion. Some of the most elegant algorithms I know use recursion. I just don’t like being forced to use it all the time.

There’s necessary complexity and unnecessary complexity. Recursion is sometimes necessary and sometimes not. With functional languages you don’t have a choice. A hammer for everything…

Could you give an example? I think it would help the discussion if we had something concrete to point to rather than speaking in generalities all the time.

You’re absolutely right, I’m guilty of not providing examples myself. It’s a bit tricky because for every possible example there does certainly exist a solution (or several), and it’s very subjective whether or not it is simple and elegant. I was just hoping that anyone who has ever used functional and imperative languages realized what I was talking about.

Anyway, geon gave a nice example. Representing a board (or even state in general) is a no-brainer in a language like C, but can be challenging in a language like Haskell. You’re often forced to find an alternative representation of the same data, so it’s easier to work with in the language. That representation can look simple and elegant to you afterwards, but that doesn’t mean it’s simple and elegant for everyone.

I guess I just love total freedom, which is why languages like C++ and recently C# attract me so much. :happy:

496dc55447c4e329e8ce8736298e51e0
0
Jack9 101 Nov 01, 2006 at 05:24

So Nick’s saying that his hammer is the Array…because a list is so much different and a DB is too slow and he doesn’t know anything about functional hashmaps. Ignorance is bliss.

receive_loop(Socket, Users) ->
io:format(“\~nstart receive_loop/2:\~p\~n”,[self()]),
{ok, Conn} = gen_tcp:accept(Socket),
io:format(“receive_loop: starting user_conn_handler child:\~p\~n”,[self()]),
UserConnPid = spawn(?MODULE, user_conn_handler, [Conn, Users]),
io:format(“receive_loop: giving user_conn_handler child control:\~p\~n”,[self()]),
gen_tcp:controlling_process(Conn, UserConnPid),
UserConnPid ! go_ahead,
io:format(“recursing receive_loop/2:\~p\~n”,[self()]),
receive_loop(Socket, Users).

Although people may mistakenly take Nick’s ignorance as fact, I find it hard to believe that someone can’t find the imperative flow of this. Line by line, this function is executed, THEN it recurses explicitly. To say you’re forced to use recursion in functional languages is inaccurate, it’s just more efficient. Also, it appears Emacs is written in LISP and some low level code in C (hence you never go “beyond functional languages”, but do program for lower level operations like drivers).

Bladder, I’m sorry I cannot speak to the “how” in Haskell. The mnesia package (soon to be native) in Erlang gives me a malleable memory-resident scaffolding. For small datasets, Erlang likes lists for up to thousands of elements.

99f6aeec9715bb034bba93ba2a7eb360
0
Nick 102 Nov 01, 2006 at 12:30

Jack9, why the offensive tone? I’m sorry if you work daily with functional programming languages and find them pefection. I don’t. I recognise the advantages but there are definite disadvantages, to me. For the things I work on, multi-paradigm languages are much better suited. Even though that’s only a personal opinion, it is true to me and I get my job done, which is high-performance game tool development. And the majority of programmers in related areas does not disagree with me. Functional programming languages are not that popular, and there’s a reason for that. But every programming language has its purpose…

So Nick’s saying that his hammer is the Array…

I was talking about loops versus recursion in that context, but nevermind.

Although people may mistakenly take Nick’s ignorance as fact, I find it hard to believe that someone can’t find the imperative flow of this.

It is perfectly possible to rewrite every functional program in an imperative form, and every imperative program in a functional form. But that doesn’t mean they are equivalent in use.

496dc55447c4e329e8ce8736298e51e0
0
Jack9 101 Nov 01, 2006 at 22:23

is a no-brainer in a language like C

It’s a no-brainer to anyone who knows C. Much like it’s a no brainer to anyone who knows Erlang.

I cannot directly make someone feel offended, that’s a personal experience which I cannot control.

I can be hostile, but I would think it’s apparent that pointing out ignorance is neither hostile nor is it unfounded. Making inaccurate statements about functional language because finding the answers is more difficult than making wild claims about unsuitability, leading to my ultimate conclusion.

limited to recursion for loops

being limited to recursion is silly

False.

for anything really serious it quickly becomes a pain. The claims about needing less code are true, but you need just as long or longer to write it down

False.

I’m aware that the compiler has a lot to do with (number crunching), but that’s a worthless excuse in practice

True.

a PhD in math to get a language to do exactly what I want then I don’t want to bother with it

A PhD in math wont help you make more efficient programs in Erlang anymore than it would help you in C. False.

Recursion is sometimes necessary and sometimes not. With functional languages you don’t have a choice.

False.

There’s not enough voices to make one conclusion seem more valid than another nor is there enough understanding to be sure. Oh yea, we’ve mixed in a fair amount of opinion. My experience teaches me the problem with FP is that it’s hard to get paid to do it in America. This will change. Regardless of what someone believes, comp.languages.functional is still a more appropriate venue to discuss issues that have arisen. Perhaps this thread could have started with Q: “where can I ask about Haskell problems?” A: Join one of the many mailing lists to air your questions and concerns to get actual answers!

:offtopic:
I can only promise that learning is taking a backseat to ego or stubborness when people argue about the uslessness of FP despite the evidence to the contrary and the failure to fully understand FPLs mentioned. Either way, this has certainly been a good show.

22b3033832c5c699c856814b0cf80cb1
0
bladder 101 Nov 02, 2006 at 05:34

Recursion is sometimes necessary and sometimes not. With functional languages you don’t have a choice.

False.

That’d depend on whether or not the FPL in question is pure or not no? in a pure FPL what Nick said is not False, it’s True. There are no “loops” in the classical sense. I believe Erlang is not pure and may or may not allow loops ala imperative, but in haskell you just can’t.

You can make a loop emulator function though…

for [] f = return ()
for (x:xs) f = f x >> for xs f

that can be used to replace for loops, you could call it like:

for [1..10] myFunction

and you get a loop from 1 to 10 that calls myFunction passing in the loop id for each “cycle”.

Nick: you may want to check out: Where Are the ‘For’ Loops

6cad28055d4af37574fe0d4064555e53
0
GroundKeeper 101 Nov 02, 2006 at 06:37

Functional languages can of course incorparate semantics for handling states and all concept avalible in a imperative language but to do so would actually spoil the reason you have a functional language.

Programming languages creates extremist religions in programmers and therefor often gets used in ways the language is never intended. To make a codec in fp would be like using only a screwdriver when building a car. Sure there are a couple of screws on there that would motivate the use but when trying to jam the engine in the tool gets kind of out of balance.

I would say C# is going the right way when actually discovering that a language can have a functional extension that will in the end make the language more powerful by being able to express funtional constructs (like lamda constructs).

When I used Haskell my teacher was of the kind that he wanted to show the greatness of Haskell by forcing us to implement a Webserver and stuff like that which of course we could but mostly it showed the things that a funtional language does poorly and with no grace at all.

I really like the syntax of functional languages for expressing functional concepts but keep it contained as a embedded language (= within a imperative language).

=)

99f6aeec9715bb034bba93ba2a7eb360
0
Nick 102 Nov 02, 2006 at 09:02

@Jack9

It’s a no-brainer to anyone who knows C. Much like it’s a no brainer to anyone who knows Erlang.

It’s not a no-brainer to anyone who knows Haskell. And while things were instantly clear to me while learning C when I was 14, it took me months to do something non-basic in Haskell when I was 22. The original post was about Haskell.

I cannot directly make someone feel offended, that’s a personal experience which I cannot control.

I don’t feel offended, I said you have an offensive tone. Yes my knowledge of functional programming is limited, but I still know enough about it to have an educated opinion of my own. I could talk about how I might doubt your knowledge of C/C++ and assembly, but I won’t.

I can be hostile…

My apologies, that’s probably the word I was looking for. Feel free to write in Dutch, French or German to avoid potential misinterpretation.

…but I would think it’s apparent that pointing out ignorance is neither hostile nor is it unfounded. Making inaccurate statements about functional language because finding the answers is more difficult than making wild claims about unsuitability, leading to my ultimate conclusion.

It is inappropriate and can be offensive. Again, I could try mentioning a potential ignorance of yours, but I won’t because it’s inappropriate and can be offensive. So unless you know everything about my life and work, I suggest keeping the discussion less personal. We’re talking about the advantages and disadvantages of functional languages here. If you can’t imagine the disadvantages I’m experciencing, there is no discussion.

False.

You are limited to recursion for loops. Even when there are constructs that look like an imperative loop, there is still recursion involved. Else it’s not a functional language, it’s an imperative or multi-paradigm language. And when I said that being limited to recursion is silly, that was a personal opinion. Is is not true or false. It is true to me and even if I change my opinion it was still true then.

False.

True to me and tons of other professional programmers. If it takes longer to write something in a functional language then there is no point using it. As I’ve said before every language has its purpose. And in game develoment C based languages rule. That’s not because of ignorance of everyone working in this business, but because of practical superiority of such languages. And I’m absolutely convinced that functional languages are superiour in other application fields.

So I suggest you stop thinking in terms of true or false, black or white, but in shades of grey or even color. Many things can be true and false at the same time, depending on the context.

A PhD in math wont help you make more efficient programs in Erlang anymore than it would help you in C. False.

Please read between the lines. Functional languages require education to use them. While someone can learn C just by experimenting with it, functional languages require lambda calculus, which is only for the math-inclined. C is intuitive to learn and use. And improving performance boils down to minimizing the number of operations. With a functional language performance can be worlds apart from what one expects, and it takes a deep mathematical understanding to improve it. Compiler implementation details are also important to reach good performance.

For certain applications it is harder to use a functional language to reach the requirements.

False.

Already colored.

There’s not enough voices to make one conclusion seem more valid than another nor is there enough understanding to be sure. Oh yea, we’ve mixed in a fair amount of opinion.

Let’s have a little recap here. Bladder asked if anyone here is using Haskell, for OpenGL/Win32 graphical applications, and to tell their experience and advantages/disadvantages compared to C/C++/C#. That’s asking for an opinion as far as I know, and that’s exactly what I gave. The fact that 99% of all OpenGL development uses C/C++/C# or other imperative/multi-paradigm languages should be a good indication of other opinions. Aguing that is pointless, and it’s certainly not an indication of any ignorance on my side.

My experience teaches me the problem with FP is that it’s hard to get paid to do it in America. This will change.

I honestly wish you the best of luck. Personally I believe that multi-paradigm languages will prevail in the areas I’m working in. Especially C# holds great promise.

I can only promise that learning is taking a backseat to ego or stubborness when people argue about the uslessness of FP despite the evidence to the contrary and the failure to fully understand FPLs mentioned. Either way, this has certainly been a good show.

I never doubted the usefulness of functional programming. It has its own advantages and I wholehartedly hope that future languages can incorporate these advantages and minimize or eliminate their disadvantages. But this discussion is leading nowhere if you cannot see these disadvantages. I’m very much looking forward to the new C# functional additions. But purely functional languages have only an educational meaning to me.

I hope bladder’s experience with Haskell is learnful. If he decides to keep using it, great. If not, I’m sure it will have made him a better C++/C# programmer.

22b3033832c5c699c856814b0cf80cb1
0
bladder 101 Nov 02, 2006 at 12:55

@Nick

I hope bladder’s experience with Haskell is learnful. If he decides to keep using it, great. If not, I’m sure it will have made him a better C++/C# programmer.

Amen…

So far I’m going pretty much in the direction you are, a little off maybe but the same general sense (imperative for games fp for academia). But my opinion is that a mixture of both would be best. You can use boost.mpl and boost.lambda (and pretty soon, boost.pheonix2) in c++ to get some pretty functional functionality into the language. There’s a presentation somewhere by Tim Sweeny on FP used in games. The gist of it is that the higher up you go the more useful FP becomes. But for low level graphics/audio/input stuff, imperative is king.

I forget the name of the article…
ah.. here

2562953b4e8e2602a8bfc24b1123a341
0
EvilSmile 101 Nov 02, 2006 at 13:02

http://www.st.cs.uni-sb.de/edu/seminare/2005/advanced-fp/docs/sweeny.pdf

Tim Sweeny talks about what he thinks should be in the next mainstream programming language and he has a few things to say about Haskell there.

2562953b4e8e2602a8bfc24b1123a341
0
EvilSmile 101 Nov 02, 2006 at 13:05

@bladder

Amen…

So far I’m going pretty much in the direction you are, a little off maybe but the same general sense (imperative for games fp for academia). But my opinion is that a mixture of both would be best. You can use boost.mpl and boost.lambda (and pretty soon, boost.pheonix2) in c++ to get some pretty functional functionality into the language. There’s a presentation somewhere by Tim Sweeny on FP used in games. The gist of it is that the higher up you go the more useful FP becomes. But for low level graphics/audio/input stuff, imperative is king.

I forget the name of the article…
ah.. here

Ah well… looks like we both posted the same thing (-:
I was reading the forums and in the end I posted without refreshing the page…

6f0a333c785da81d479a0f58c2ccb203
0
monjardin 102 Nov 03, 2006 at 04:25

@bladder

(imperative for games fp for academia). But my opinion is that a mixture of both would be best.

I’m really getting an appreciation for closures and proper tail recursion in mixing Lua with C/C++.

6ad5f8c742f1e8ec61000e2b0900fc76
0
davepermen 101 Nov 03, 2006 at 10:18

I like erlang…

D3b6eb5931a6c91d4956911a930a924b
0
JuNC 101 Nov 09, 2006 at 11:07

I like Erlang too, and Yaws rules :) Not sure about using it for game development, but building a MUD with Mnesia and embedded Yaws has been at the back of my mind for a long time..

OCaml seems more suited to games IMO, but then it’s not pure and does actually feature looping constructs :D

http://www.cse.unsw.edu.au/\~pls/thesis/munc-thesis.pdf

For a 3D game written in Haskell using FRP (Functional Reactive Programming). I admit this is not actually a good paper for arguing for Haskell being easy to understand!!

2562953b4e8e2602a8bfc24b1123a341
0
EvilSmile 101 Mar 14, 2007 at 08:01

I just started with Haskell early this morning. It seems to be an affair that is going to last quite a while. I am smitten :)

F7a4a748ecf664f189bb704a660b3573
0
anubis 101 Mar 16, 2007 at 09:19

@EvilSmile:

It will occupy you for some time…
Basically for every language feature you understand they invent two new ones :)