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
Create values and functions tutorial #1512
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.
A few new comments/suggestions and a few that were outdated from before (just in case they were lost in the shuffle). If you didn't want to make those changes or it didn't clarify, we can work on them together if necessary.
|
||
### Values | ||
|
||
Like most functional programming languages, OCaml is an [expression-oriented programming language](https://en.wikipedia.org/wiki/Expression-oriented_programming_language). There are no [statements](https://en.wikipedia.org/wiki/Statement_(computer_science)), i.e., syntactical constructions made to produce some change of state. Variable [assignments](https://en.wikipedia.org/wiki/Assignment_(computer_science)) or [for loop](https://en.wikipedia.org/wiki/For_loop) are examples of statements. Computations triggered by OCaml are written as expressions. Once completed, they produce a value, which has a type. Here are a few examples of expressions, their type, and resulting values. |
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 would phrase the difference between expressions and statements this way: the evaluation of a an expression yields a value, the evaluation of a statement yields an effect, i.e. a change of state. In many languages expressions can still yield effects and so the distinction between is not always clear cut. The same is true in OCaml where expressions and effects can be mixed.
Co-authored-by: Christine Rose <christinerose@users.noreply.github.com>
Co-authored-by: Christine Rose <christinerose@users.noreply.github.com>
Co-authored-by: Christine Rose <christinerose@users.noreply.github.com>
Co-authored-by: Christine Rose <christinerose@users.noreply.github.com>
This reverts commit 13d2dde.
This is the first tutorial after “Get Started” This tutorial introduces basic data types in OCaml. Its goal is to teach skills on how to handle data from predefined, variant, and record types. It also includes the important concept of pattern matching on those types. Outline: 1. Predefined Types 1.1. Integers, Floats, Booleans, and Characters 1.2. Strings & Byte Sequences 1.3. Arrays & Lists 1.4. Options & Results 1.5. Tuples 1.6. Functions 1.7. Unit 2. User-Defined Types 2.1. Variants 2.2. Polymorphic Data Types 2.3. Records 2.4. Type Aliases 3. A Complete Example: Mathematical Expressions --------- Co-authored-by: Cuihtlauac ALVARADO <cuihtmlauac@tarides.com> Co-authored-by: Christine Rose <christinerose@users.noreply.github.com> Co-authored-by: sabine <sabine@users.noreply.github.com>
This is an intermediate level tutorial.
The main goal is to master the concepts of definition, scope and environment. It covers definitions of functional and non-functional values.
https://staging.ocaml.org/docs/values-and-functions