"Thus, it is possible to have a variable representing the entire infinite list of Fibonacci numbers." Except that Haskell has no variables- nothing is mutable, as they say. You could certainly write a function that generates an infinite list of Fibonacci numbers when called (and lazily evaluated later), but it won't be bound to a variable. If it was, then the list would take up an infinite amount of memory, and lazy evaluation would be pointless.
- "Expression?" I don't know Haskel, but that's what I would call it in another functional language. --Rael (talk) 16:31, 3 January 2014 (UTC)
- That's a little imprecise, as it doesn't capture the idea of binding a value to a single symbol. 126.96.36.199 17:03, 3 January 2014 (UTC)
- The sentence you quote is entirely correct... but might itself require further explanation!
- Haskell variables aren't mutable, but they are nonetheless referred to as "variables". It's an appeal to the (earlier, after all) use of the word in maths, rather than in imperative programming languages. (No shortage of variables in algebra, geometry, calculus, topology... And no mutation involved.) One might equally say "symbol", "constant", or indeed "symbolic constant".
- One can bind the fibonaccis to a variable (... constant, 0-place definition, etc) quite happily. In fact, that's the idiomatic way to do it, as it avoids the degenerate complexity of a naive recursive function. It's still evaluated lazily, all the same. (Meaning that it will take an infinite amount of memory... if you run it for an infinite amount of time, and never "consume" the result in any way.)
- Equally, one can regard such top-level symbol definitions as functions with no arguments, if that's more helpful. 188.8.131.52 16:42, 3 January 2014 (UTC)
- Shows what I know about Haskell jargon, even if I do know something about the language. I see what you're saying, though.
- In any case, here's some Haskell code that does indeed generate an infinite list of Fibonacci numbers. It's not fast, and there's almost certainly more efficient ways to do it, but it's simple enough that people unacquainted with the language should be able to figure it out.
fibonaccis :: [Integer] --Indicates that the function returns a list of arbitrary-length integers fibonaccis = map fib [0..] --Converts the infinite list [0,1,2,3,4...] into a list of Fibonaccis where fib n --Defines a helper function that returns the nth Fibonacci number |n == 0 = 1 --The zeroth and first Fibonaccis are 1 |n == 1 = 1 |otherwise = (fib (n - 1)) + (fib (n - 2)) --And the rest are the sum of the previous two.
- And here's one which is closer to what an Haskeller would write (if he ever needed to compute Fibonacci numbers and couldn't bother using one of the good (non-linear) algorithms) :
fibs :: [Integer] fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
- The first two numbers are 0, 1 and you get the rest by adding fibs and tail fibs (fibs offset by 1 element) (zipping them together with +).
- The surprising part is that fibs is used in its own computation but that's no problem since each needed element can be computed by the time you need it (we "primed the pump" with the first two elements) and Haskell has lazy evaluation (sometimes named "call-by-need").
- Note that this version only compute each element once, contrary to the previous one (which is horrendous since it does the whole inefficient (O(fib n)) Fibonacci computation for each element).
- --Jedaï (talk) 00:38, 26 January 2014 (UTC)
- You can add xmonad (tiling window manager) to the list, as well as darcs for a time (though git has thoroughly dominated this field by now...), you can also use Hakyll to generate your static blog (which presents some advantage in performance and safety), hoodle is a good free pen note taking program, hledger is a ledger handling program with several backends. The game Nikki and the robots is written in Haskell. --Jedaï (talk) 00:38, 26 January 2014 (UTC)
- I think the person Nealmcb who updated the incomplete tag to say " Add examples of popular Haskell programs" is boarderline trolling if not full on trolling -- Explanation looks pretty complete to me and I vote to remove the incomplete tag. Spongebog (talk) 01:59, 4 January 2014 (UTC)
"thus Haskell may have value but no one has either invoked it to get that value or requested such a language." The point of the title text is (a joke that) programmers of Haskell are lazy, but no one tells them so. The point is not that no one uses Haskell. That is the point of the comic itself. 184.108.40.206 (talk) (please sign your comments with ~~~~)
... I am confused by the description. Is it possible that someone can put this into "plain language" that a non-programmer and a non-mathematician can understand? (Go ahead and add "slow" to that description, too, if you so choose...) 220.127.116.11 09:11, 5 January 2014 (UTC)
- Functional programming languages are many -- explaining the difference to a non-programmer can be hard, but typically Lisp as the grandfather and related languages such a Scheme, Haskell [ list here ] are considered functional programming languages, where Java, C, Basic, Fortan etc typically depending on changing state of variables and are called Procedural or Imperative programming programming languages -- The best advice for futher explanation is to read the wikipedia links. Spongebog (talk) 18:22, 5 January 2014 (UTC)