News for hackers. Stuff that matters.
Re:Why don't we use functional programming languages more? (... by evilthinker on Sunday October 17, 2010 @04:17PM (#1801297)
Prelude> head [] * Exception: Prelude.head: empty list

Damn I think might need to trace this one.

Re:Why don't we use functional programming languages more? (... by nickik on Sunday October 17, 2010 @05:18PM (#1801456)
I thought that this was implemented.

I Clojure its like this: (first []) --> nil

What is in that list? Answer nothing.

I think thats a way to go too.

Re:Why don't we use functional programming languages more? (... by frio on Sunday October 17, 2010 @05:25PM (#1801472)
I haven't used Clojure, so excuse me if there's something I'm missing here, but doesn't that mean that the following is true?

    first [nil] == first []
In which case, I prefer the Haskell way, as it's more specific.
Re:Why don't we use functional programming languages more? (... by pufuwozu on Sunday October 17, 2010 @06:45PM (#1801649)

    user=> (= (first [nil]) (first []))
    true
Re:Why don't we use functional programming languages more? (... by stusmith1977 on Monday October 18, 2010 @07:04AM (#1802963)
I strongly disagree. If you're expecting the first value of a list, what use is nil?

If you have a list of Ints, then what can you do with nil returned? It's not an Int.

Nils have a habit of propagating through the whole type system, and you then need to have rules about how they apply to every function. (What is 1+nil? What is nil:[1,2,3]?).

Eventually every single function will either have odd behaviour when confronted with a nil, or will be a source of exceptions (which are generally undesirable in a pure functional setting).

Haskell encourages you to write patterns that check for these edge cases, and handle them explicitly:

foo [] = ...

foo (x:xs) = ...

Re:Why don't we use functional programming languages more? (... by nickik on Thursday October 21, 2010 @10:50AM (#1815620)
Why would you have nil in a list of integers? In cases where you encounter nil instead of some type you look for you can add behavior to nil without doing if nil? in the function all the time.

I would agree that not having nil is better if you have these big typesystems but for a dynamic languge its hard to avoid.

Question: Don't these static langauge use "unit" to signal what nil would do in clojure (in some casses)?