Comments (3)
Thanks a bunch for reporting this and providing an explanation of what's happening.
PR to fix in #97
from purescript-book.
So the example has been updated for better style and to remove warnings. However, this issue still occurs and the parenthesis still fix it. While this is a simple fix, I feel like it would be nice to provide an explanation. Sadly, I don't myself understand it.
from purescript-book.
The example isn't correct; it needs the parentheses because of precedence rules (the function is being applied to acc
and then we add one to the result).
This code:
length' (fromMaybe [] $ tail arr) acc + 1
is parsed like this:
(length' (fromMaybe [] $ tail arr) acc) + 1
instead of the way it's intended from my reading of the example, which is:
length' (fromMaybe [] $ tail arr) (acc + 1)
Just to check this, I threw it into try.purescript.org and looked at the output, and indeed the version without parenthesis emits this JS:
return length$prime(Data_Maybe.fromMaybe([ ])(Data_Array.tail(arr$prime)))(acc) + 1 | 0;
which is adding 1 to the result of length'
after it is called on acc
, which isn't going to fire the TCO (or increment the accumulator).
So I'd suggest just fixing the example without further explanation -- it's not that this is a tricky case, it's just that the example is incorrect.
from purescript-book.
Related Issues (20)
- [Ch3] Indentation docs for `where` are wrong HOT 1
- :memo: Chapter 8 standard form label use HOT 1
- Chapter 11 HOT 1
- chapter 10 duplicated mapSetFoo instead of alternative
- chapter 10 double negation intended or typo? HOT 2
- Chapter 9, final exercise description improvement HOT 1
- Error in Handbook - Asynchronous Effects
- Update Book to PureScript `0.15.0` HOT 2
- Chapter 10: Confusion between `id` and `identity` functions HOT 4
- Getting Started scripts - not all lines are removed
- error ERR_REQUIRE_ESM following instructions in Getting Started HOT 1
- Example from book fails on freebsd HOT 3
- [CH4] A more concise implementation of fibTailRec. HOT 1
- Warning about not using latest spago.
- Swap of Ch4 and Ch5 incomplete HOT 1
- Ch6: Subclass/Superclass confusion for `Ord`/`Eq`
- Not clear that Exercise should include subdirectories
- Can you clarify this no peeking stuff? HOT 3
- Chapter 2, Pythagorean theorem
- Upgrade to the latest package set
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from purescript-book.