-
Notifications
You must be signed in to change notification settings - Fork 323
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
Tutorial on Mutability and Imperative Programming #1529
Conversation
043fd39
to
b534ee4
Compare
eb8c037
to
699771e
Compare
fbb4d33
to
9f20f43
Compare
Hi,
why not "Note: This example will not run in the REPL, since the function Array.truncate is not defined." Why not use Not too sure about the "Analytics" example. I would avoid depending on code that is left to the reader to imagine. I think you could achieve the same effect by logging something in a or on stderr. I would maybe start this part by a more general remark saying that in OCaml, side-effects do not occur in types (whether they are modification of mutable state or exceptions). That is a strength (allows you to use local side effects, or functions that behaves as-if they were pure but more efficient) but also a problem since, when the side effect is actually part of the spec, one has to rely on documentation to be aware of that (e.g. a function that mutates its argument). As for side effects in arguments I would generalize a bit saying that this also apply to constructor argument and that code such as:
may return different values depending on the back-end, optimization level, version of the compiler etc… |
Fixed
If we show code which is bad but somehow working, it will be copied and used. truncate is way to work around that (analytics undefined too).
I like the idea you suggest about adding text. What I like about analytics is the discrepancy between copying an array and opening a network connection. But you are right, we should not assume everybody knows about analytics and provide some details
Excellent example! |
Mutable Data: references, records and arrays/bytes Imperative Exceptions Howto mix styles without getting into trouble Refunctionalization techniques
7bf11a7
to
86c04db
Compare
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.
Questions found in my review
``` | ||
In this example, the first two expressions are `print_endline` function calls, which produce side effects (printing to the console), and the last expression is simply the integer `42`, which becomes the value of the entire sequence. The `;` operator is used to separate these expressions. | ||
|
||
**Remark** Even thought it's called the sequence operator, the semicolon is not truly an operator because it is not a function of type `unit -> 'a -> 'a`. It is rather a _construct_ of the language. That allows terminating sequences with a semicolon, which is ignored. |
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.
Please check my revision here to ensure it's still accurate. 🙂
# let state = ref [] in try loop state with Exit -> state_to_string !state;; | ||
``` |
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.
Since this doesn't return anything but just leaves a space for more input, should we mention that or clarify it's necessary to return twice to get back to the prompt?
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 need to fix offline
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.
We need to say something like:
Type and edit any single line text, and then press return to get back to the repl
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.
A few questions
Anything left to do before me merge this? |
Mutable Data: references, records and arrays/bytes
Imperative
Exceptions
Howto mix styles without getting into trouble
Refunctionalization techniques