Talk:1312: Haskell

Explain xkcd: It's 'cause you're dumb.
Revision as of 19:52, 3 January 2014 by Someone Else 37 (talk | contribs) (Added some Haskell sourcecode)
Jump to: navigation, search

"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.

I will, however, leave the above word "variable" in the explanation, because I can't come up with a concise way of explaining the above. --Someone Else 37 (talk) 09:07, 3 January 2014 (UTC)

"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. 108.162.231.13 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. 108.162.231.13 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.
--Someone Else 37 (talk) 19:52, 3 January 2014 (UTC)

Does anyone have a clue what the Incomplete flag refers to? This seems like a pretty good explanation to me. --Mynotoar (talk) 11:22, 3 January 2014 (UTC)

Example programs written in Haskell are: pandoc, universal markup converter; git-annex, tool to manage large files in git DVCS. --JakubNarebski (talk) 11:37, 3 January 2014 (UTC)