News for hackers. Stuff that matters.
Re:Why Haskell is beyond ready for Prime Time by jimbokun on Wednesday January 14, 2009 @03:17PM (#434200)
Object orientation eventually "won" in the market. Unfortunately, it was adopted by the general programming public in the form of Java, not Smalltalk.

It seems like functional programming is similarly "winning" as an idea. Anyone who thinks about programming much agrees that a language where you can't pass a function as a value, or construct functions at runtime, is pretty broken.

The question then, is whether Haskell is the new Smalltalk of functional programming, and what language will play the role of the functional programming Java.

Re:Why Haskell is beyond ready for Prime Time by andreyf on Wednesday January 14, 2009 @05:32PM (#434448)
The question then, is [...] what language will play the role of the functional programming Java.

JavaScript?

Re:Why Haskell is beyond ready for Prime Time by 11ren on Thursday January 15, 2009 @07:33AM (#435092)
I think part of Lisp's success was that academics liked it, so when they did clever stuff, it was related to Lisp. Today, it seems that academics like Haskell (is it true?), and so when they think of clever stuff, it will be related to Haskell.

The "Java of FP" could be C# or F# (although Microsoft isn't willing to go multi-platform, so that might stop it becoming "successful", by many definitions).

But honestly, I don't think there is a powerful enough vector available to carry FP. C had Unix. Java had the net. A novel way to think about the next "Java of FP" is to think of what vector could matter, and then what FP language is well-placed to be carried by it.

Mobile phones are all I can think of at the moment, but no FP has come of it; the netbooks (which are becoming phones) are plain ol' PCs; and the iPhone runs Objective-C (doesn't it?). What's the next IT revolution?

Actually, time_management is right: the next IT revolution is clearly multi-core.

EDIT: I keep hearing about Intel's CUDA for multicore on GPU's, but it's pretty much the anti-FP, being "recursion free" http://en.wikipedia.org/wiki/CUDA#Limitations

Re:Why Haskell is beyond ready for Prime Time by 11ren on Saturday January 17, 2009 @07:11PM (#438780)
There's a counter-argument to multi-cores being the next IT revolution: although they seem to be the way to faster performance, faster performance isn't needed.

Data point one: the rise of the netbook. They have slower, single-core processors, and are fast enough for most of the mainstream stuff people want to do: web, email, word-processing. Netbooks are getting faster (and this is needed for some webapps e.g. that musical score webapp is a little sluggish on my eee PC). But what is more important in a netbook is weight and battery life - that is what is needed. Performance isn't needed.

Data point two: even in video games, the wii console is the most successful of the present batch. It is unusually low powered even for single-core (and in coincidence, one of its competitors, the PS3, is multi-core). Performance isn't needed.

Data point three (an exception): some applications do need performance (weather simulation; google server farms), but these are already multi-core, and have been for a long time (the core used to be in separate computers, but the app was multi-core).

I'm arguing that most of the mainstream market can't absorb faster performance (and the high-performance market has already solved the problem).

Ripe for Disruption?: It's common for whole industries to overshoot what is needed, in terms of the particular metric they have worked at improving for years. Their corporate organization, product development and marketing are based on improving that aspect, and selling that aspect. When the basis of competition shifts, you get a new set of leaders, because the old ones can't adapt.

Re:Why Haskell is beyond ready for Prime Time by ionfish on Thursday January 15, 2009 @08:57AM (#435126)
There's a project called GpuGen intended to allow the compilation of Haskell code to CUDA.

http://www.galois.com/blog/2008/08/29/gpugen-bringing-the-po...

There's also something similar called Obsidian:

http://lambda-the-ultimate.org/node/3016

Re:Why Haskell is beyond ready for Prime Time by ionfish on Thursday January 15, 2009 @09:27AM (#435154)
And if you'd prefer to read the original papers, rather than presentation slides...

http://www.cse.unsw.edu.au/~chak/papers/gpugen.pdf

http://www.cse.chalmers.se/~joels/writing/dccpaper_obsidian....

Re:Why Haskell is beyond ready for Prime Time by 11ren on Thursday January 15, 2009 @08:55PM (#436051)
I think Haskell is intellectually challenging in a way that isn't needed to get the job done. The one exception is for proving things (which so far is not practical - but it's cool, and might become practically useful, one day).

Don't get me wrong: I like the intellectual challenge, and I especially like the Haskell community - they are nice people, excited about what they're doing, very helpful, and just not interested in putting down other languages - and I think there is real beauty in Haskell. It's like a branch of mathematics.

Disclosure: I'm terrible at Haskell's intellectual challenge. It makes me feel stupid. I hate that.

Re:Why Haskell is beyond ready for Prime Time by wmf on Wednesday January 14, 2009 @03:45PM (#434242)
Indeed; all functional languages are not alike. Haskell is not just functional, it's also lazy and has "weird" syntax. If functional programming is going to take off, I would expect to see it in the form of an eagerly-evaluated language with C-like syntax.
Re:Why Haskell is beyond ready for Prime Time by eelco on Wednesday January 14, 2009 @03:50PM (#434246)
Maybe I'm getting Haskell-blind, but what's "wierd" about the syntax? If I think about "wierd" syntax, I think about Erlang or Objective-C or Befunge for that matter. However, it seems that once you spent a day or so with a language the syntax wierdness tends to go away. (Still need to test that hypothesis with Erlang, though.)
Re:Why Haskell is beyond ready for Prime Time by lacker on Wednesday January 14, 2009 @03:59PM (#434265)
Pattern-matching for control flow rather than if statements is the main weird thing. E.g.

  sum ys = 
	  let sum' [] total = total
	      sum' (x:xs) total = sum' xs (total+x)
	  in sum' ys 0
That looks weird.
Re:Why Haskell is beyond ready for Prime Time by silentbicycle on Wednesday January 14, 2009 @04:49PM (#434359)
Unlike some other features* , pattern matching isn't all that scary, though. "Oh, it's like a switch statement... but it can break things up and check inside... that's pretty cool." You can understand it in terms of other fairly commonplace constructs, and it's relatively clear how useful it is.

It could be presented a bit differently, but the underlying idea seems approachable.

* I'm thinking of monads, in particular; whether they actually are or whether it's just due to the way they've been presented is another question.

Re:Why Haskell is beyond ready for Prime Time by time_management on Thursday January 15, 2009 @12:00AM (#434837)
Monads aren't that hard. A monad is just like a burrito!

Pattern matching is awesome. It makes code immensely more readable.

Re:Why Haskell is beyond ready for Prime Time by silentbicycle on Thursday January 15, 2009 @07:50AM (#435101)
I started to understand monads when I compared the Maybe monad to the short-circuiting behavior of the Unix pipe. That doesn't mean my insight will work for anybody else, though.

Also, having masses of Haskell blog posts saying, "No, monads are actually not that hard, here's (an explanation that probably won't actually make all that much sense)." probably doesn't help to dispel the myth that Haskell is hard / impractical / whatever.

Re:Why Haskell is beyond ready for Prime Time by time_management on Thursday January 15, 2009 @08:59AM (#435128)
In understanding monads, I think Maybe and List are the best places to start, because they're familiar data structures. IO is conceptually familiar, but IO as an immutable value representing a series of actions is not.
Re:Why Haskell is beyond ready for Prime Time by silentbicycle on Thursday January 15, 2009 @01:21PM (#435451)
Agreed, strongly. Trying to understand monads in terms of IO makes things vastly more difficult than necessary.
Re:Why Haskell is beyond ready for Prime Time by time_management on Friday January 16, 2009 @12:25AM (#436191)
Well, just as "monads are like burritos", IO is like a delicious but sketchy fish taco. Eating is input. We shan't discuss the output process; we all know how it works and what it looks like. Food poisoning or poor health can lead to usage of standard error. In practice, stdout and stderr are usually redirected to the same buffer, which is flushed shortly after a write.
Re:Why Haskell is beyond ready for Prime Time by ighost on Monday February 02, 2009 @11:33PM (#463502)
brilliant.
Re:Why Haskell is beyond ready for Prime Time by felixmar on Wednesday January 14, 2009 @04:56PM (#434374)
A case expression is more common:

  sum ys = sum' ys 0
    where sum' list total =
      case list of
        []   -> total
        x:xs -> sum' xs (total + x)
Re:Why Haskell is beyond ready for Prime Time by wernerv0nbraun on Wednesday January 14, 2009 @11:49PM (#434827)
this haskell example is exposing you to two cool things:

- algebraic types. haskell has type inference, so it can do the right thing while you only describe the function as operating on lists. now look at java...strong typing but no intelligent inference, which is why you are forced to write retarded java like HashSet<Integer> s = new HashSet<Integer>()

- pattern matching. you can describe functionality based on the pattern of the data

this isn't just syntax. these are really powerful fundamental features of the language

Re:Why Haskell is beyond ready for Prime Time by lacker on Thursday January 15, 2009 @03:17PM (#435651)
Yes, I totally agree. But the question I was responding to was just, "What parts of Haskell have weird syntax?" All of this cool stuff would also be possible with c-like syntax.
Re:Why Haskell is beyond ready for Prime Time by brl on Thursday January 15, 2009 @01:14AM (#434913)
Retarded? Really?

I guess that you don't know that generics in Java were derived from Haskell type classes and designed by the same man who added monads to Haskell.

Re:Why Haskell is beyond ready for Prime Time by fhars on Thursday January 15, 2009 @07:26AM (#435088)
Retarded, indeed. Almost half of that code is a redundant repetition of type information.
Re:Why Haskell is beyond ready for Prime Time by brl on Thursday January 15, 2009 @11:47AM (#435309)
It's not redundant information and in Haskell you write exactly the same thing.

  doSomething :: HashSet Int -> HashSet Int
Re:Why Haskell is beyond ready for Prime Time by jganetsk on Thursday January 15, 2009 @07:17PM (#435964)
And that man would absolutely love it if Java had a type system closer to Hindley-Milner with type inference. But, given the reality of Java, generics become undesirably verbose.
Re:Why Haskell is beyond ready for Prime Time by brl on Thursday January 15, 2009 @08:01PM (#436009)
A typical well written Haskell program has more type annotation than the same program written in Java. Not only that but because of type classes those annotations are even more verbose than an equivalent declaration in Java.

It's true that you can omit most of the type signatures and let the compiler figure it out but nobody really writes Haskell code that way if they want it to be comprehensible by human readers.

Re:Why Haskell is beyond ready for Prime Time by silentbicycle on Friday January 16, 2009 @12:01AM (#436178)
I've wondered about this. It seems common for OCaml code to only have the type annotations where necessary, but it's usually included in Haskell by convention.
Re:Why Haskell is beyond ready for Prime Time by eru on Thursday January 15, 2009 @11:34AM (#435292)
He had to work in the constraints of the language..
Re:Why Haskell is beyond ready for Prime Time by tphyahoo on Thursday January 15, 2009 @10:24AM (#435212)
sum ys = foldl' (+) 0 ys
Re:Why Haskell is beyond ready for Prime Time by eru on Thursday January 15, 2009 @11:36AM (#435294)
Combinators for the win!
Re:Why Haskell is beyond ready for Prime Time by wmf on Wednesday January 14, 2009 @04:03PM (#434272)
Pattern matching, also the lack of syntax for function calls (I realize there's a good reason for it).
Re:Why Haskell is beyond ready for Prime Time by jimbokun on Thursday January 15, 2009 @12:46PM (#435398)
"lack of syntax for function calls"

It recently dawned on me that this is what makes it hard for me to understand snippets of Haskell. Specifically, trying to parse the precedence relations in a sequence of tokens uninterrupted by any kind of punctuation.

Say what you will about Lisp, it is always very clear which arguments go to which functions, what the scoping boundaries are, etc.

Re:Why Haskell is beyond ready for Prime Time by eru on Tuesday January 20, 2009 @01:09AM (#441449)
In Haskell you can just put your parens like you would in Lisp.
Re:Why Haskell is beyond ready for Prime Time by ighost on Monday February 02, 2009 @11:34PM (#463503)
But a lot of people use $ syntax.
Re:Why Haskell is beyond ready for Prime Time by lallysingh on Wednesday January 14, 2009 @04:45PM (#434348)
C++ 0x is providing lambdas and closures. Closures didn't make it into Java, where it may have been relevant.
Re:Why Haskell is beyond ready for Prime Time by time_management on Thursday January 15, 2009 @12:05AM (#434842)
Multi-core concurrency is going to kill OO. FP will resurge in the 2010s among good programmers, spreading out to the "vital 25%" (who are, right now, mostly upper-tier Java developers) rather than being restricted to an elite 3-5%.
Re:Why Haskell is beyond ready for Prime Time by 11ren on Thursday January 15, 2009 @07:12AM (#435078)
I know this is the conventional wisdom, but can you provide support for your claim that multi-core will help FP?

The usual claim is that the immutability of FP will avoid the problems of different processes writing to shared memory, because they only read it.

But Erlang is famous for its concurrency, and this is not due to it being a FP; it is due to its shared-nothing pure-message passing (from Smalltalk). It's another solution.

If you have multi-cores, the problem is not what you do within one core (we can already manage that); it's that you have many cores. If [1] they have their own local memory, then pure-message passing is the inevitable solution.

Anyway, that's my reasoning - I'm interested to hear your reasoning.

[1] At the moment, the on-chip memory is (very small) cache, and so shared memory is an option... but I think it's also inevitable that we'll get sufficient local memory for each core to execute code independently.

Re:Why Haskell is beyond ready for Prime Time by cstejerean on Thursday January 15, 2009 @09:13AM (#435137)
erlang is really good at running distributed programs. that's where the share nothing actor model is necessary and works well. it's actually a kludge to write a simple concurrent application in erlang because the simplest reads requires sending two messages. For writing concurrent applications (single process, multiple threads) I like the Clojure approach much better. I can't explain it length here, but check out http:/clojure.org
Re:Why Haskell is beyond ready for Prime Time by time_management on Thursday January 15, 2009 @09:14AM (#435139)
I think Clojure is likely to shoot ahead of Erlang as the leading concurrency language. After that will be Concur, an ML/Haskell-inspired statically-typed concurrency language my friend Brian Hurt is designing.

One thing I've picked up, looking at Clojure, is that the lack of mutable state allows certain cool optimizations. For example, let's say you have a map A with a million key-value pairs. You want to do something with B = A + (k', v'). In a mutable-state language, you'd physically add (k', v') to the map, which is usually implemented as a hash table. Clojure creates a new map (32-ary tree) for B that shares most of its pointers and structure with A, which allows you to do FP without FP's greatest drawback, which is the copying of large data structures. Since the nodes will never change, this sharing is entirely safe. A remains entirely unchanged, so a thread working with A still has A.

Functional programming doesn't actually eliminate side effects and mutability. Haskell has the IO and Array monads. Clojure has refs and agents. FP simply segregates them from the rest of the program so that they exist only when desirable, and can be more easily managed.

I don't know the details about cache and local memory. This is a weak area for me.

Re:Why Haskell is beyond ready for Prime Time by eru on Thursday January 15, 2009 @11:32AM (#435291)
> FP's greatest drawback, which is the copying of large data structures

I guess you made that one up on the spot. Go read about "Purely Functional Data Structures" http://www.cs.cmu.edu/~rwh/theses/okasaki.pdf or have a look at Haskells Data.Map implementation for another example.

Re:Why Haskell is beyond ready for Prime Time by time_management on Thursday January 15, 2009 @12:49PM (#435403)
I meant that it's the greatest (potential) drawback of the functional style, especially when that style is employed in a non-purely functional language. You're correct that you don't often end up doing full-object copies in the leading implementations of certain purely functional languages, such as Haskell or Clojure.
Re:Why Haskell is beyond ready for Prime Time by eru on Thursday January 15, 2009 @03:45PM (#435694)
The design of good persistent (i.e. 'functional') data structures remains an art. But you do not have to rely on the designers of your language.

Hey, you can even simulate Haskell's lazyness to implement some Persistent Data Structures efficiently in Java.

Re:Why Haskell is beyond ready for Prime Time by 11ren on Thursday January 15, 2009 @08:49PM (#436043)
Q. If you append to a linked list, you can't avoid creating an entirely new copy of the list, can you? (prepending is OK, because you reuse the old list).

Or can Haskell's laziness help with this? Can it somehow avoid actually creating the new copy, but instead just return the correct value when you reach the end of the list? So that the new copy is never actually made, but it just behaves as if it was?

Re:Why Haskell is beyond ready for Prime Time by time_management on Friday January 16, 2009 @12:20AM (#436189)
There's a trick for efficient appending that's somewhat analogous to laziness. It's quite clever. Sadly, I cannot claim to have come up with it, and I don't know who did.

Instead of working with [a] lists, work with [a] -> [a] prepender functions. So the analogue of [1, 2, 3] is f: \x -> [1 2 3] ++ x. Then the analogue of the append of f and 4 is f . (\x -> [4] ++ x), where the . represents composition. Appending using these analogues, I believe, is O(1) instead of O(n).

To "evaluate" an element of this "closure space", just apply it to the empty list.

Re:Why Haskell is beyond ready for Prime Time by eru on Monday January 19, 2009 @04:22AM (#440260)
You can also re-use some form of balanced binary trees where all interesting operations are doable in log(n) and adding requires about log(n) (mostly internal) nodes to be rebuild. That is worse than the optimum O(1) for linked lists you can reach --- but it's easy to come up with and often good enough.