Update frriendly.md and a type error message

This commit is contained in:
Richard Feldman 2023-10-06 20:29:51 +02:00
parent 5ed8bade21
commit 55f1e82dbb
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B
2 changed files with 58 additions and 37 deletions

View file

@ -1,24 +1,55 @@
# Friendly
Roc is intended to be a user-friendly language with a friendly community.
Roc prioritizes being a user-friendly language. This impacts the syntax, semantics, and tools Roc ships with.
## User-friendly language
## Syntax and source code formatter
- Concise syntax, e.g. just `=` for declarations, no parentheses or commas needed when calling functions (maybe don't focus on conciseness though)
- anonymous structural literals for records, tuples, and tag unions, all of which have Eq, Hash, and Ord inferred automatically
- String interpolation
- `Dec` by default
Roc's syntax isn't trivial, but there also isn't much of it to learn. Its design is generally uncluttered and umabiguous. A goal is that you can normally look at a piece of code and quickly get an accurate mental model of what it means, without having to think through several layers of indirection. Here are some examples:
### Helpful compiler
- `user.email` always means the `email` field of a record named `user`. There's no inheritance, subclassing, or proxying to consider, and this will always do the same thing regardless of what's imported (because there are traits or implicits to consider either).
- `Email.isValid` always refers to a constant (probably a function) named `isValid` in a module named `Email`. (Module names are always capitalized, and variables never are.) Modules are always defined statically and can't be modified at runtime; there's no monkeypatching to consider.
- `x = combine y z` always declares a new constant `x` (Roc has [no mutable variables, reassignment, or shadowing](/functional)) to be whatever the `combine` function returns when passed the arguments `y` and `z`. (Function calls in Roc don't need parentheses or commas.)
- `"My name is \(Str.trim name)"` uses *string interpolation* syntax: a backslash inside a string literal, followed by an expression in parentheses. This code is the same as combining the string `"My name is "` with the string returned by the function call `Str.trim name`. Because Roc's string interpolation syntax begins with a backslash (just like other backlash-escapes such as `\n` and `\"`), you can always tell which parts of a string involve special handling: the parts that begin with backslashes. Everything else works as normal.
- Nice error messages
- If you like, you can run a program that has compile-time errors. It will crash when it gets to the error. (Note that this currently fails a lot, and has a ways to go.)
Roc also ships with a source code formatter that helps you maintain a consistent style with little effort. The `roc format` command neatly formats your source code according to a common style, and it's designed with the time-saving feature of having no configuration options. This feature saves you all the time that would otherwise be spent debating which stylistic tweaks to settle on!
## Helpful compiler
Roc's compiler is designed to help you out. It does complete type inference across all your code, and the type system is sound. This means you'll never get a runtime type mismatch if everything type-checked (including null exceptions; Roc doesn't have the billion dollar mistake), and you also don't have to write any type annotations for the compiler to be able to infer all the types in your program.
If there is a problem at compile time, the compiler is designed to report it in a helpful way. Here's an example:
```
── TYPE MISMATCH ────────────────── /home/my-roc-project/main.roc ─
Something is off with the `then` branch of this `if` expression:
4│ someInteger : I64
5│ someInteger =
6│ if someDecimal > 0 then
7│ someDecimal + 1
^^^^^^^^^^^^^^^
This branch is a fraction of type:
Dec
But the type annotation on `someInteger` says it should be:
I64
Tip: You can convert between integers and fractions using functions like
`Num.toFrac` and `Num.round`.
```
If you like, you can run a program that has compile-time errors like this. (If the program reaches the error at runtime, it will crash.) This lets you do things like trying out code that's only partially finished, or running tests for one part of your code base while other parts have compile errors. (Note that this feature is only partially completed, and often errors out; it has a ways to go before it works for all compile errors!)
## Serialization inference
### Serialization inference
- Type inference is used for schema inference, but you can also spell it out if you like
- Reports errors immediately
### Tools built in
## Testing
You can run `roc test` to run all your tests. Each test is declared with the `expect` keyword, and can be as short as one line. For example, this is a complete test:
@ -33,21 +64,9 @@ In the future, there are plans to add built-in support for [benchmarking](https:
- also note: future plan to cache tests so we only re-run tests whose answers could possibly have changed. also maybe note: tests that don't perform I/O are guaranteed not to flake b/c pure functions.
#### Formatting
`roc format` neatly formats your source code so you don't have to. It also doesn't have any configuration options, so collaborators can spend time on things other than negotiating settings.
#### Package management
- Currently just URLs (content-hashed to make them immutable)
- No installation step, global cache of immutable downloads instead of per-project folders (no need to .gitignore anything)
- There is a design for a searchable package index, but it hasn't been implemented yet.
#### Future plans
## Future plans
- Package manager (Currently just URLs, content-hashed to make them immutable) with searchable index and no installation step, global cache of immutable downloads instead of per-project folders (no need to .gitignore anything)
- Step debugger with replay
- Customizable "linter" (e.g. code mods, project-specific rules to enforce)
- Editor plugin ecosystem that works across editors, where plugins ship with packages
- `roc edit`
## Friendly community
<3