-
Notifications
You must be signed in to change notification settings - Fork 90
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
Another example for const #214
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems sensible to me, although I think we should avoid ==
and use =
instead, because ==
implies we are using an Eq instance, which doesn’t exist. It’s more consistent with the rest of the file that way too.
Was there a particular case of confusion which prompted this, by the way?
src/Data/Function.purs
Outdated
@@ -26,6 +26,12 @@ flip f b a = f a b | |||
-- | ```purescript | |||
-- | const 1 "hello" = 1 | |||
-- | ``` | |||
-- | | |||
-- | Can also be thought of as creating a function that ignores its argument: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if this style is used elsewhere, but I prefer using complete sentences, either be prefixing with "It can also be...", or referring to the name again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just basing this on the previous line which is also a fragment:
Returns its first argument and ignores its second.
I tend to read cons 1 [2, 3, 4] = [1, 2, 3, 4] But I agree that Maybe there's a third option. Clojure examples tend to use a newline prefixed by (map inc [1 2 3 4 5])
;;=> (2 3 4 5 6)
I was confused by this early on, or at least it took a bit of reasoning through to figure out how the description of |
Yes, some programmers are more used to seeing “=“ mean assignment rather than equality, but basically everyone is aware that “=“ can mean equality, and I think it’s clear from context that equality, not assignment, is meant here. In cases where there is an Eq instance I’m not desperately concerned about whether “=“ or “==“ is used, but I don’t agree that “=“ makes less sense. What is meant by “=“ is that both sides of the equation are indistinguishable within a program: you can freely replace the left hand side with the right and vice versa, and your program won’t behave differently. I think that’s the correct way of thinking about cases like this, too. The Clojure examples like that mean “if you enter the stuff on the first line at the repl, you’ll get the stuff on the second line printed out”. This is also a good option in many cases, but it doesn’t work here because functions aren’t printable. |
Updated PR with review feedback. Probably best to squash these two lazy web edits together when merging. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Found an exception to the claim that right-hand side can be replaced with left-hand-side. Compilation error when substituting -- Main.purs
foreign import equal :: forall a. a -> a -> Boolean
eqEqual :: forall a. Eq a => a -> a -> Boolean
eqEqual = equal
data AB = A | B
main :: Effect Unit
main = do
logShow $ equal A B -- false
-- logShow $ eqEqual A B -- compile error // Main.js
exports.equal = a => b => a === b; Originally documented here. |
Where is it claimed that your |
Just basing that on the line:
```hs
eqEqual = equal
```
|
Oh, I see what you mean. The = in docs examples is a different = from the one you find in PureScript source files. In docs examples, it’s equality, an assertion that two expressions behave the same. In source files, it’s definition. For example, it makes sense to write |
No description provided.