Earlier quoted context omitted.
> does Haskell even have a stack? Yes
While this is true, the contents of the STG stack aren't necessarily obviously related to the conceptual "call stack", right?
Destroy All Ifs – A Perspective from Functional Programming
221–226 of 226 posts
Re: Destroy All Ifs – A Perspective from Functional Programming
#222Earlier quoted context omitted.
Thats why you use Lua, it lets you have multiple return values. So you can get a boolean back to let you know if the strings were the same, an int to know where they ceased matching and a boolean to let you know if they are case different. It's then up to the programmer to decide how much enlightenment they want. The destroy all IF reminds me of GOTO considered harmful of the 70's. There are other ways to fix the pro…
What's the difference between multiple return values and returning a tuple? (Apart from that languages with multiple return values tend to have some special syntax for binding only the first few members of the returned tuple?)
Re: Destroy All Ifs – A Perspective from Functional Programming
#223Earlier quoted context omitted.
The point of tail recursion is using constant space, not constant stack space (does Haskell even have a stack?) Anyways, the Haskell spec allows foldl' to use linear space just like its lazier counterparts. The fact that it uses constant space is an implementation detail of GHC. Reference: https://github.com/quchen/articles/blob/master/fbut.md#seq-d... Structural recursion always terminates in SML. Supporting infinit…
Tail recursion can't use constant space if it's strictly generating another data structure of the same size. That doesn't even make sense. Interesting fact about foldl'. Regardless, in practice it is strict and tail recursive. As I mentioned earlier, this does not mean the same thing as constant space unless the reduction function returns a fixed size result. Yes, you can guarantee that a linked list in Java is finit…
What about another thread running that keeps generating pieces to the end of the linked list? (No problem, with mutation.)
Re: Destroy All Ifs – A Perspective from Functional Programming
#224Re: Destroy All Ifs – A Perspective from Functional Programming
#225Earlier quoted context omitted.
Tail recursion can't use constant space if it's strictly generating another data structure of the same size. That doesn't even make sense. Interesting fact about foldl'. Regardless, in practice it is strict and tail recursive. As I mentioned earlier, this does not mean the same thing as constant space unless the reduction function returns a fixed size result. Yes, you can guarantee that a linked list in Java is finit…
> Yes, you can guarantee that a linked list in Java is finite because Java does not support codata. What about another thread running that keeps generating pieces to the end of the linked list? (No problem, with mutation.)
class LinkedList {
public final T value;
public final LinkedList next;
public LinkedList(T value, LinkedList next) {
this.value = value;
this.next = next;
}
}
Here's how you construct it: LinkedList myList =
new LinkedList("Hello",
new LinkedList("World", null));
Here's how you iterate over it in constant space: while (myList != null) {
System.out.println(myList.value);
myList = myList.next;
}Re: Destroy All Ifs – A Perspective from Functional Programming
#226Earlier quoted context omitted.
They don't have `other primitives': they have function calls. Most languages have function calls these days.
Yes, I read LTUI and LTUD. But in most languages, function calls and loops don't have the same semantics. I'll call that a different loop primitive.
(At least for C as encountered in the wild, I don't know about C the standard.)
Most modern C compilers support tail call optimization.
I don't know about `most languages'. Eg I know Java on the JVM doesn't do tail call optimization. Lots of languages probably do not require TCO of their implementations, though.