Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursion Discussion #10

Closed
dgstevens opened this issue Jan 6, 2015 · 5 comments
Closed

Recursion Discussion #10

dgstevens opened this issue Jan 6, 2015 · 5 comments

Comments

@dgstevens
Copy link

I'll preface this by saying that my knowledge of Haskell is intermediate at best, but the discussion on recursion seems to fall somewhere between misleading and wrong. Many recursive functions are not tail-recursive - the factorial example isn't, for instance. It's possible to transform function to be tail-recursive, but I would be surprised if such transformations are the default behavior of any Haskell compiler at -O0. I especially would hesitate to speculate on the implementation of recursion due to Haskell's laziness.

As a side note, the mutually recursive examples have extraneous semicolons.

@sdiehl
Copy link
Owner

sdiehl commented Jan 6, 2015

Entering a function in Haskell does not create a new stack frame, the logic of the function is simply entered with the arguments on the stack and yields result to the register.

There is no mention of tail recursion in this section explicitly for this reason. The only point I wanted to make is that stack frames are not created when jumping to entry code for a function.

@dgstevens
Copy link
Author

So I just did some quick reading about Haskell's runtime. What's confusing to me about this section is that it mentions the Haskell stack but doesn't actually discuss that the stack in Haskell is different from stacks in most other languages. Without knowing that fact, the obvious conclusion from the fact that the factorial code can crash with a stack overflow is that the paragraph is wrong in some manner. And I will say that I'm probably a pretty good candidate for this tutorial - I've written a compiler for an imperative language before in Haskell, so I don't think my lack of knowledge about the Haskell runtime is unusual.

@sdiehl
Copy link
Owner

sdiehl commented Jan 6, 2015

Well, I implemented a Haskell runtime in Chapter 23 anyways so I'm not going to stress of the exact phrasing of the introduction comment.

@sdiehl sdiehl closed this as completed Jan 7, 2015
@dgstevens
Copy link
Author

Just my two cents, but phrasing in the introduction of a tutorial is very important.

The fact that the tutorial discusses the Haskell runtime in Chapter 23 implies that Chapter 2 doesn't assume knowledge of the Haskell runtime in the introduction. And that in turn means that Chapter 2 could very likely be seen as wrong by the targets of the tutorial, which could lead people to lose confidence and abandon the tutorial.

Another example where phrasing is important in the introduction is Chapter 1's section on static typing. Those two examples are very intimidating for anyone that does not have a good grasp of type systems. So even though later chapters go over that material, I'm sure many readers will give up during the introduction because there is no indication that the tutorial does not assume they understand those examples.

@sdiehl
Copy link
Owner

sdiehl commented Jan 8, 2015

I'm welcome to changing the phrasing or adding qualifiers. Submit a change for how you'd like to see the sentence changed.

https://github.com/sdiehl/write-you-a-haskell/blob/master/001_basics.md

The same goes for the examples on static typing.

@sdiehl sdiehl reopened this Jan 8, 2015
@sdiehl sdiehl closed this as completed Jan 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants