You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tutorials/09_elm-intro.md
+27-2Lines changed: 27 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -618,6 +618,31 @@ profile =
618
618
619
619
_Note_: There are two more complex techniques, how to design data structure - opaque types (next lesson) and phantom types.
620
620
621
+
### Never type - Never
622
+
623
+
Never type is a type that doesn't have any values. It's a type that can be specified in a type annotation, but you can't construct a Never value because it is valueless.
624
+
625
+
### Unit type - ()
626
+
627
+
Unit type is commonly used as a placeholder for an empty value.
628
+
629
+
```elm
630
+
type alias Message a =
631
+
{ code :String
632
+
, body : a
633
+
}
634
+
635
+
readMessage:MessageString->String
636
+
readMessage message =
637
+
...
638
+
639
+
readEmptyMessage:Message()->String
640
+
readEmptyMessage message =
641
+
...
642
+
```
643
+
644
+
_Note_: `readEmptyMessage` function takes Message with an empty body. This is not the same as any value, just an empty one.
645
+
621
646
### Pattern Matching
622
647
623
648
```elm
@@ -808,7 +833,7 @@ Elm has several operators for chaining functions and function calls together.
808
833
`|>` operator takes a value and a function and applies the function to the value. It is useful when chaining more steps together to write readable code.
809
834
810
835
```elm
811
-
pipe:: a-> (a->b) ->b
836
+
pipe:a-> (a->b) ->b
812
837
pipe =
813
838
(|>)
814
839
@@ -824,7 +849,7 @@ greet3 maybeName =
824
849
`<|` operator is the opposite. It takes a function and a value and apply the function to the value. It is useful to avoid parentheses, the same as `$` in Haskell.
Copy file name to clipboardExpand all lines: tutorials/10_elm-tea.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,7 +35,7 @@ We can then define our own type for Todo item and a decoder.
35
35
```elm
36
36
importJson.DecodeasDecode
37
37
38
-
type alias TodoItem=
38
+
type alias Todo=
39
39
{ id :Int
40
40
, label :String
41
41
, completed :Bool
@@ -198,12 +198,12 @@ import Email
198
198
199
199
emailView:Email.Email->Htmlmsg
200
200
emailView =
201
-
Email.toString
202
-
>>Html.text
201
+
Email.toString
202
+
>>Html.text
203
203
204
204
emailView2:String->Htmlmsg
205
205
emailView2 =
206
-
Html.text
206
+
Html.text
207
207
```
208
208
209
209
_Note_: From `Email` module, we expose only `Email` type without variant `EmailInternal`. The only way, how to access email value is in this module, no other module does not have access to `EmailInternal` and can use only access function `toString`.
0 commit comments