Conversation
- Merge of types-01 commit 5100108 Author: Luke Seale <19484084+lbseale@users.noreply.github.com> Date: Fri Nov 5 06:42:35 2021 -0700 Add types module Covering - Static Type - Type Inference - Bools, Ints, Floats, Chars, Text - Why we don't use String
| negativeInteger :: Integer | ||
| negativeInteger = -37 | ||
| ``` | ||
|
|
There was a problem hiding this comment.
Any chance you could add a little something about Word? I'm especially interested in promoting it as a type that can't be negative, instead of using Int and hoping for the best. It's also the occasion to evoke the correct by construction paradigm.
There was a problem hiding this comment.
Consider mentioning Natural instead of or together with Word?
There was a problem hiding this comment.
And the fact that arithmetic underflows are handled differently:
When doing 0 - 1
- Since
Wordis modular, it loops back to18446744073709551615 - In the case of
Natural, anarithmetic underflowexception is thrown
| ```haskell | ||
| someText :: Text | ||
| someText = "Let's learn Haskell" | ||
| ``` |
There was a problem hiding this comment.
Could you add a couple of examples for Text? Especially the functions that do not exist in base for String?
| ## Static Typing | ||
|
|
||
| Haskell is a statically-typed programming language. This means that the type | ||
| of all data must be known before the program is compiled. Some imperative |
There was a problem hiding this comment.
| of all data must be known before the program is compiled. Some imperative | |
| of all data must be known before the program is executed. Some |
| Instead of declaring the type of every single function and variable, Haskell | ||
| can *infer* the type of values based on just a few declarations. | ||
|
|
||
| Typically, you just need to specify the type of a function. The types of all |
There was a problem hiding this comment.
Since this isn't actually required, consider saying something like this instead:
while Haskell does not require type annotations in most cases, it is good practice to annotate the types of top-level definitions. This adds an extra layer of documentation, and safety where the Haskell compiler can verify our intent (as expressed in the type annotation) matches the code.
| ## Type Declarations | ||
|
|
||
| In Haskell, you declare types on a separate line from where they are used. | ||
| Even though I said above that you usually only declare types for functions, in |
There was a problem hiding this comment.
You can avoid this line by saying "top-level definitions"
| Type inference is a killer feature of Haskell, and once you get used to it, you | ||
| won't want to work without it. | ||
|
|
||
| ## Type Declarations |
There was a problem hiding this comment.
Consider changing this to "type signatures" or "type annotations", so it won't be confused with declaring new types (using data/newtype/etc)
| ``` | ||
|
|
||
| The fact that `Int`'s size is limited means it is subject to overflows. These | ||
| occur without warning, so if they are a concern, use `Integer` |
There was a problem hiding this comment.
| occur without warning, so if they are a concern, use `Integer` | |
| occur without warning, so if they are a concern, use `Integer`. |
|
|
||
| import Data.Text ( Text ) | ||
| ``` | ||
|
|
There was a problem hiding this comment.
Maybe add "we'll explain why this is needed later" or something similar?
|
|
||
| `Text` is more convenient, performant and capable than `String`. We want | ||
| beginners to avoid the mistakes of the past and start off with good | ||
| practices, so we have chosen to teach `Text`. |
There was a problem hiding this comment.
Maybe this would be a good place to mention that text lives in a different package/module, what overloadedstrings does, and how to convert String <-> Text?
Add types module
Covering (for now)
This is just the start, I plan to add more details
Submitter checklist