-
Notifications
You must be signed in to change notification settings - Fork 190
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
Better explanation of flip function #260
Comments
Excellent feedback. Thanks. I recall flip being pretty mind-melting for me when learning Elm the first time, but having paid those FP dues, I didn't catch this as being confusing in the PureScript book. I think the solution is to fix the library docs and perhaps link to the Pursuit entry from the book. I'm not a fan of the existing Pursuit example, since Also, great workaround for linking to lines in markdown. Annoying that isaacs/github#297 has been on the wish list for the past 6 years. |
I think Something like this could be a good sequence: Let's say we want to perform truncating division by 5 on each element of an array of integers.
This first attempt is not quite right:
We're mixing up the argument order and dividing 5 by each element of the array instead.
It's more concise with
But most concise by using
|
+1 on Chapter 3 suddenly getting very difficult when |
Would this orientation help? flip :: forall firstArg secondArg returnType
. (firstArg -> secondArg -> returnType)
-> secondArg
-> firstArg
-> returnType
flip functionABToC b a = functionABToC a b
append "hello" "world" == "helloworld"
flip append "hello" "world" == "worldhello"
-- flip's type signature can be simplified
flip :: forall a b c.
. (a -> b -> c)
-> b
-> a
-> c
flip f b a = f a b |
I like the first two lines or so:
... but then I'm getting lost in the rest. For me at least, As a PureScript beginner coming from JavaScript, I'd like to spend a bit more time getting used to the syntax this early on, as it's pretty different to JavaScript. Getting the hang of the functional nature of PureScript could maybe come a bit later? Just me thinking out loud though... :) |
As a complete beginner I had a very hard time to understand the example for
flip
. I didn't saw any practical use in the example.I found a great example and explanation on stackoverflow which opened my eyes on the use of
flip
The licence for the stackoverflow post would be
CC BY-SA 3.0
according to stackoverflow/licensing. Is this compatible with the current licence? Any thoughts on including the stackoverflow post?The text was updated successfully, but these errors were encountered: