-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
ch11: fix saveComment definition #500
base: master
Are you sure you want to change the base?
Conversation
Function `saveComment` in this chapter is defined as composition of functions, one of which is `getValue('#comment')`. However, `getValue('#comment')` is not a function according to its type specification: ```js // getValue :: Selector -> Task Error (Maybe String) ``` This fixes the definitions of `saveComment` to avoid type mismatch.
Nice catch. What about using: https://github.com/MostlyAdequate/mostly-adequate-guide/blob/master/appendix_a.md#always ? |
I tried, but unfortunately we can't use `always` to wrap an object of type `a` into a no-argument function `() -> a`, since it waits for the second argument:
```js
always(1) //=> function
always(1)() //=> function
always(1)(2) //=> 1
```
So `always(getValue('#comment'))()` returns a function, whereas `(_ => getValue('#comment'))()` returns a Task.
|
I am not sure to follow you on that one. We have: always :: a -> b -> a
getValue :: Selector -> Task Error (Maybe String)
getValue("#comment") :: Task Error (Maybe String) Hence: always(getValue("#comment")) :: b -> Task Error (Maybe String) Which should run perfectly fine in the pipeline; it's an unary function returning a |
Exactly, but as I recall from reading the book always(getValue("#comment"))() :: b -> Task Error (Maybe String) I may be wrong about the |
Hmmm. That is incorrect. The type for Functions don't usually take |
It's not, and you can try it to see for yourself: > always(Task.of(1))
[Function: always]
> always(Task.of(1))()
[Function: always]
> always(Task.of(1))(undefined)
Task(?)
Translating to JavaScript, this means that So the functions in this example must be called like I also found a couple of places where a function is called with no arguments, but I guess I will make another PR to fix that. |
Hi,
Function
saveComment
in this chapter is defined as a composition of functions, one of which isgetValue('#comment')
. However,getValue('#comment')
is not a function according to its type specification:// getValue :: Selector -> Task Error (Maybe String)
This patch fixes the definitions of
saveComment
to avoid type mismatch.