Skip to content

Commit f2b0a80

Browse files
ceddlyburgempizenbergcedd burge
authored
Basics-2 concept and associated exercise (#329)
* Add skeleton for bettys bike shop exercise / foundations concept * Add test, code and examplar * Add instructions for bettys bike shop * Add design document for bettys bike shop * Add links for foundations concept * Add foundations concept information * Update introduction to match about * Update hints and links, which seem very similar Maybe I have misunderstood their respective purposes a bit * Add some full stops in design.md * Compliance with updated markdown spec in #330 * Move exporting before importing Exporting introduces the notion of exposing and was already introduced in the previous concept so putting it first seems more natural to me. * Ajustments to the import section * Tiny fixes in type annotation section * Adjustment to the string section * Tiny fixes in instructions * Rename basics to basics-1 * Rename foundations concept to basics-2 * Split pence to string conversion in to 2 steps * Rename foundations to basics-2 * Fix typo ELm -> Elm in config.json * Fix title level of basics-1 concept * Update bettys-bike-shop config.json to latest spec * Move concept blurbs to their own .meta/config.json * Add a missing level 1 title to basics-2/introduction.md * Small improvements on Betty's introduction.md * Back-propagate Betty's doc improvement to concept docs * Add a number section in basics-2 docs * Update betty's instructions to match the spec Co-authored-by: Matthieu Pizenberg <[email protected]> Co-authored-by: cedd burge <[email protected]>
1 parent ccbc74b commit f2b0a80

File tree

20 files changed

+554
-7
lines changed

20 files changed

+554
-7
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"authors": [
3+
"mpizenberg"
4+
],
5+
"contributors": [
6+
"ceddlyburge"
7+
],
8+
"blurb": "Learn the basic syntax of an Elm file"
9+
}

concepts/basics/about.md renamed to concepts/basics-1/about.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Elm syntax basics
1+
# Elm syntax basics 1
22

33
## Constants and functions
44

File renamed without changes.
File renamed without changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"authors": [
3+
"ceddlyburge"
4+
],
5+
"contributors": [
6+
"mpizenberg"
7+
],
8+
"blurb": "Learn the basics of Elm programming"
9+
}

concepts/basics-2/about.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Elm syntax basics 2
2+
3+
## Exporting functions
4+
5+
Exporting functions was covered in the first concept, here is a quick refresher.
6+
7+
Each file in Elm is a module and must contain a `module` statement before all other code.
8+
9+
Module names must match their file name, so module `Calculator` must be in file Calculator.elm, and module `Parser.Utils` needs to be in file Parser/Utils.elm.
10+
11+
Anything defined within a module is privatly scoped to it and cannot be accessed from outside this module, unless listed in `exposing`.
12+
13+
```elm
14+
-- Calculator.elm
15+
-- Define the Calculator module, and expose the `add` function
16+
module Calculator exposing (add)
17+
18+
six = 3 + 3
19+
20+
add number1 number2 = number1 + number2
21+
```
22+
23+
```elm
24+
-- Calculator.elm
25+
-- Define the Calculator module, and expose everything within: `six` and `add`
26+
module Calculator exposing (..)
27+
28+
six = 3 + 3
29+
30+
add number1 number2 = number1 + number2
31+
```
32+
33+
https://elm-lang.org/docs/syntax#modules
34+
35+
## Importing functions from other modules
36+
37+
Accessing functions defined in other modules is done via imports.
38+
All functions within that module that were exposed by it are made accessible when importing that module.
39+
But how they are accessed varies depending on how the module is imported.
40+
41+
Qualified imports are the default, and accessing a function within such module (for example the `map` function in the `List` module) is done by prefixing the module name (`List.map`).
42+
43+
Open imports enable direct access to the exposed functions within that module, without prefixing. They are done with the `exposing` keyword, like a mirror to the one used in exports. You can expose all available functions (with `..`), or specific ones (for example `map`).
44+
45+
You can also import types, and their constructors from other modules, which is a later concept.
46+
47+
Qualified imports are preferred to aid clarity and avoid name clashes.
48+
49+
```elm
50+
-- qualified imports
51+
import List -- List.map, List.foldl
52+
import List as L -- L.map, L.foldl
53+
54+
-- open imports
55+
import List exposing (..) -- map, foldl, concat, ...
56+
import List exposing ( map, foldl ) -- map, foldl, List.concat
57+
```
58+
59+
https://elm-lang.org/docs/syntax#modules
60+
61+
## Type annotations
62+
63+
Type annotations are defined with `name : parameter types -> return type`, parameter types also being separated by `->`.
64+
65+
```elm
66+
add : Int -> Int -> Int
67+
add number1 number2 = number1 + number2
68+
```
69+
70+
Parentheses can be used to define function parameters (which are themselves defined with the same syntax, hence the need for brackets).
71+
72+
```elm
73+
-- Transform every character in a string
74+
map : (Char -> Char) -> String -> String
75+
map charMapperFunction string =
76+
-- ...
77+
```
78+
79+
https://elm-lang.org/docs/syntax#type-annotations
80+
81+
## Numbers
82+
83+
There are two types of numbers available in Elm, defined by the `Int` and `Float` types.
84+
`Int` corresponds to the set of positive and negative integers.
85+
`Float` corresponds to the set of real numbers, limited by the precision of the computer.
86+
Operations defined on numbers usually work on one type or the other, but not mixing them.
87+
There exists functions to convert between the two, such that `toFloat` which converts `Int` to `Float` and `round`, `floor`, `ceiling` or `truncate` which convert a `Float` to an `Int` with different semantics.
88+
89+
https://package.elm-lang.org/packages/elm/core/latest/Basics#Int
90+
91+
## String operations
92+
93+
To describe words and sentences in code, Elm has a native `String` type.
94+
String literals are written between double quotes such as `"Hello World!"`.
95+
A string concatenation operator `++` and equality operator `==` are available by default.
96+
97+
```elm
98+
hello : String -> String
99+
hello subject = "Hello " ++ subject
100+
101+
hello "World!" --> "Hello World!"
102+
```
103+
104+
Most other string functions are in the `String` module, which needs to be imported.
105+
106+
https://package.elm-lang.org/packages/elm/core/latest/String

concepts/basics-2/introduction.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Introduction
2+
3+
## Exporting functions
4+
5+
Exporting functions was covered in the first concept, here is a quick refresher.
6+
7+
Each file in Elm is a module and must contain a `module` statement before all other code.
8+
9+
Module names must match their file name, so module `Calculator` must be in file Calculator.elm, and module `Parser.Utils` needs to be in file Parser/Utils.elm.
10+
11+
Anything defined within a module is privatly scoped to it and cannot be accessed from outside this module, unless listed in `exposing`.
12+
13+
```elm
14+
-- Calculator.elm
15+
-- Define the Calculator module, and expose the `add` function
16+
module Calculator exposing (add)
17+
18+
six = 3 + 3
19+
20+
add number1 number2 = number1 + number2
21+
```
22+
23+
```elm
24+
-- Calculator.elm
25+
-- Define the Calculator module, and expose everything within: `six` and `add`
26+
module Calculator exposing (..)
27+
28+
six = 3 + 3
29+
30+
add number1 number2 = number1 + number2
31+
```
32+
33+
https://elm-lang.org/docs/syntax#modules
34+
35+
## Importing functions from other modules
36+
37+
Accessing functions defined in other modules is done via imports.
38+
All functions within that module that were exposed by it are made accessible when importing that module.
39+
But how they are accessed varies depending on how the module is imported.
40+
41+
Qualified imports are the default, and accessing a function within such module (for example the `map` function in the `List` module) is done by prefixing the module name (`List.map`).
42+
43+
Open imports enable direct access to the exposed functions within that module, without prefixing. They are done with the `exposing` keyword, like a mirror to the one used in exports. You can expose all available functions (with `..`), or specific ones (for example `map`).
44+
45+
You can also import types, and their constructors from other modules, which is a later concept.
46+
47+
Qualified imports are preferred to aid clarity and avoid name clashes.
48+
49+
```elm
50+
-- qualified imports
51+
import List -- List.map, List.foldl
52+
import List as L -- L.map, L.foldl
53+
54+
-- open imports
55+
import List exposing (..) -- map, foldl, concat, ...
56+
import List exposing ( map, foldl ) -- map, foldl, List.concat
57+
```
58+
59+
https://elm-lang.org/docs/syntax#modules
60+
61+
## Type annotations
62+
63+
Type annotations are defined with `name : parameter types -> return type`, parameter types also being separated by `->`.
64+
65+
```elm
66+
add : Int -> Int -> Int
67+
add number1 number2 = number1 + number2
68+
```
69+
70+
Parentheses can be used to define function parameters (which are themselves defined with the same syntax, hence the need for brackets).
71+
72+
```elm
73+
-- Transform every character in a string
74+
map : (Char -> Char) -> String -> String
75+
map charMapperFunction string =
76+
-- ...
77+
```
78+
79+
https://elm-lang.org/docs/syntax#type-annotations
80+
81+
## Numbers
82+
83+
There are two types of numbers available in Elm, defined by the `Int` and `Float` types.
84+
`Int` corresponds to the set of positive and negative integers.
85+
`Float` corresponds to the set of real numbers, limited by the precision of the computer.
86+
Operations defined on numbers usually work on one type or the other, but not mixing them.
87+
There exists functions to convert between the two, such that `toFloat` which converts `Int` to `Float` and `round`, `floor`, `ceiling` or `truncate` which convert a `Float` to an `Int` with different semantics.
88+
89+
https://package.elm-lang.org/packages/elm/core/latest/Basics#Int
90+
91+
## String operations
92+
93+
To describe words and sentences in code, Elm has a native `String` type.
94+
String literals are written between double quotes such as `"Hello World!"`.
95+
A string concatenation operator `++` and equality operator `==` are available by default.
96+
97+
```elm
98+
hello : String -> String
99+
hello subject = "Hello " ++ subject
100+
101+
hello "World!" --> "Hello World!"
102+
```
103+
104+
Most other string functions are in the `String` module, which needs to be imported.
105+
106+
https://package.elm-lang.org/packages/elm/core/latest/String

concepts/basics-2/links.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[
2+
{
3+
"url": "https://elm-lang.org/docs/syntax#modules",
4+
"description": "Modules"
5+
},
6+
{
7+
"url": "https://elm-lang.org/docs/syntax#type-annotations",
8+
"description": "Type annotations"
9+
},
10+
{
11+
"url": "https://package.elm-lang.org/packages/elm/core/latest/Basics#Int",
12+
"description": "Integers"
13+
},
14+
{
15+
"url": "https://package.elm-lang.org/packages/elm/core/latest/Basics#Float",
16+
"description": "Floats"
17+
},
18+
{
19+
"url": "https://elmprogramming.com/string.html",
20+
"description": "String chapter of Beginning Elm"
21+
},
22+
{
23+
"url": "https://package.elm-lang.org/packages/elm/core/latest/String",
24+
"description": "String module"
25+
}
26+
]

config.json

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,13 @@
5858
"concepts": [
5959
{
6060
"uuid": "3e6e4a21-cc66-4c48-857b-90e1ca5298f9",
61-
"slug": "basics",
62-
"name": "Basics",
63-
"blurb": "Learn basics of the Elm programming language syntax."
61+
"slug": "basics-1",
62+
"name": "Basics 1"
63+
},
64+
{
65+
"uuid": "e850acd6-63f3-427e-a883-222e0bd89a59",
66+
"slug": "basics-2",
67+
"name": "Basics 2"
6468
}
6569
],
6670
"files": {
@@ -84,11 +88,22 @@
8488
"name": "Lucian's Luscious Lasagna",
8589
"uuid": "54b70493-702b-4577-9d47-ec5ede4cc2c1",
8690
"concepts": [
87-
"basics"
91+
"basics-1"
8892
],
8993
"prerequisites": [],
9094
"status": "wip"
95+
},
96+
{
97+
"slug": "bettys-bike-shop",
98+
"name": "Betty's Bike Shop",
99+
"uuid": "88818c16-fff8-4964-b9a4-c799833ff970",
100+
"concepts": [
101+
"basics-2"
102+
],
103+
"prerequisites": [ "basics-1" ],
104+
"status": "wip"
91105
}
106+
92107
],
93108
"practice": [
94109
{
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Hints
2+
3+
## General
4+
5+
- Basic integer operators are described in elm [Basics module documentation][basics-int].
6+
- Basic float operators are described in elm [Basics module documentation][basics-float].
7+
- String functionality is described in [String chapter of Beginning Elm][string-beginning-elm] and in the elm [String module documentation][string-module].
8+
9+
[basics-int]: https://package.elm-lang.org/packages/elm/core/latest/Basics#Int
10+
[basics-float]: https://package.elm-lang.org/packages/elm/core/latest/Basics#Float
11+
[string-beginning-elm]: https://elmprogramming.com/string.html
12+
[string-module]: https://package.elm-lang.org/packages/elm/core/latest/String

0 commit comments

Comments
 (0)