Reputation
10,894
Next privilege 15,000 Rep.
Protect questions
Badges
10 48 107
Newest
 Guru
Impact
~697k people reached

Dec
16
comment How to make the transition to functional programming?
@scarfridge: Update. In the mean time I have read "Learn You a Haskell for Great Good" and it is definitely a very good introduction. It gives a lot of examples and helps build a good intuition.
Dec
8
comment Does immutability hurt performance in JavaScript?
Also, consider that there exist efficient implementations of immutable data structures. Maybe these are not as efficient as mutable ones, but probably still more efficient than a naive implementation. See e.g. Purely Functional Data Structures by Chris Okasaki
Dec
6
comment Why is behavorial subtyping undecidable?
@Doval: Very good point. While it is true that you cannot have an algorithm that proves termination and / or correctness of a random program, it is possible to write programs in such a way that you can prove their correctness.
Dec
3
comment What is the conceptual difference between finally and a destructor?
In C++, why is the destructor called automatically only with a stack object and not with a heap object in case of an exception?
Dec
2
comment How does “repeat x = x:repeat x” return a list in Haskell?
@AndresF.: "I'm sure you replied to me by mistake.": I have overlooked your other comments and answers about Haskell, so I did not need to give such a detailed explanation. Maybe we can meet in chat some time and discuss what a list actually is? I find the topic interesting. I would prefer to discuss it in chat so we can clean up the comments here.
Dec
2
comment What is LPCTSTR?
"There were two flavors of pointers under 16-bit windows": Does the name come from back then? Some compilers used to call them far pointers...
Dec
2
comment How does “repeat x = x:repeat x” return a list in Haskell?
@AndresF.: In what sense does (1 : 2: undefined) "break" lists while (undefined : 1 : []) doesn't? Both have undefined as argument to the : value constructor.
Dec
2
comment How does “repeat x = x:repeat x” return a list in Haskell?
@AndresF: In Haskell, a list is really either the empty list [], or a term of the form t : ts. Whether t and ts evaluate to something meaningful only matters when you want to examine them. Try typing length (undefined : 1 : []), you get 2! Why? Because you do not need to look at the elements of a list in order to find its length, you only need to count how many : it contains before reaching [] (assuming the list is finite and you do reach a [] eventually).
Dec
2
comment How does “repeat x = x:repeat x” return a list in Haskell?
@AndresF: If you type it in the ghci REPL you get: [1,2,3*** Exception: Prelude.undefined. But if you type: take 3 (1 : 2 : 3 : undefined), lo and behold, you get [1,2,3]! Why? Because the term is evaluated lazily: once take has gotten 3 elements out of the term, it does not proceed to evaluate the undefined and so no exception is thrown.
Dec
2
awarded  Nice Answer
Dec
1
comment How does “repeat x = x:repeat x” return a list in Haskell?
Note that there are many ways to process streams of data: you can create them lazily (Haskell), you can iterate over them (e.g. in Python), you can use callbacks to be notified when a new value is ready (see reactivex.io/intro.html)
Dec
1
comment How does “repeat x = x:repeat x” return a list in Haskell?
The word stream has had a well-defined meaning at least since the 1980s (SICP). Also, I do not think that the concept of a stream used for IO is very far from that. Only the way in which you access a stream of data varies. When you are calling getc() in C you are actually pulling the next byte from a potentially infinite list / stream.
Dec
1
comment How does “repeat x = x:repeat x” return a list in Haskell?
@MasonWheeler: An output stream is like an input stream, with producer and consumer swapped.
Dec
1
comment How does “repeat x = x:repeat x” return a list in Haskell?
I have added, for each evaluation step, the equation being used. You just match and replace subexpressions until you are finished.
Dec
1
revised How does “repeat x = x:repeat x” return a list in Haskell?
added 164 characters in body
Dec
1
comment How does “repeat x = x:repeat x” return a list in Haskell?
The interpreter does what is shown above: each time it needs a new element it replaces repeat' 3 with 3 : repeat' 3. Of course, this only works in a context (like in a call to take) where the remaining repeat' 3 is eventually thrown away.
Dec
1
comment How does “repeat x = x:repeat x” return a list in Haskell?
repeat' will never give you that [], take will. Because take 0 _ = []. I.e. if you call take with the first argument 0, it does not look at the second argument (which contains the nasty infinite stuff) and returns []. And everything is nice again.
Dec
1
comment How does “repeat x = x:repeat x” return a list in Haskell?
@MasonWheeler: In Scala they are called streams: scala-lang.org/api/current/…
Dec
1
comment How does “repeat x = x:repeat x” return a list in Haskell?
@MasonWheeler: Scala, SML, Scheme, Lisp, to make a few examples. See also the book SICP which uses scheme but illustrates the concept from an abstract point of view. You can easily implement them in Java, Python, etc using delayed evaluation.
Dec
1
revised How does “repeat x = x:repeat x” return a list in Haskell?
added 458 characters in body