Skip to content

Commit 09d8709

Browse files
committed
Update tut04 for B252
1 parent 923c487 commit 09d8709

3 files changed

Lines changed: 596 additions & 527 deletions

File tree

tutorials/01_fp-env.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ We can read this as: the expression `"Hello"` is of type `String` (`::` means "*
200200

201201
This is the first math connection worth making explicit:
202202
* In mathematics, we say that an object has a certain type or belongs to a certain set, e.g., `5 ∈ ℤ` (alt. `5 : ℤ`) means that the number `5` is an integer.
203-
* In Haskell, we say that an expression has a certain type, e.g., `5 :: Int` means that the expression `5` is of type `Int`.
203+
* In Haskell, we say that an expression has a certain type, e.g., `5::Int` means that the expression `5` is of type `Int`.
204204

205205
Types are not decoration — they are part of the meaning of the program. The type system helps ensure correctness, guides program structure, and enables powerful abstractions. **Type inference** means that you often do not need to write types explicitly; GHC can figure them out for you. It does so by analyzing how expressions are constructed and combined. It always tries to find the most general type that fits the expression.
206206

tutorials/03_branching.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -304,13 +304,13 @@ It is important to distinguish between:
304304
* `otherwise` – a `Bool` expression equal to `True`
305305

306306
```
307-
Prelude> :t otherwise
308-
Prelude> otherwise == True
307+
ghci> :t otherwise
308+
ghci> otherwise == True
309309
True
310-
Prelude> not otherwise
310+
ghci> not otherwise
311311
False
312312
otherwise :: Bool
313-
Prelude> :t _
313+
ghci> :t _
314314
315315
<interactive>:1:1: error:
316316
• Found hole: _ :: t
@@ -621,7 +621,7 @@ Only the arguments that are actually used are evaluated. This is a direct conseq
621621

622622
Some operations cannot proceed without actual values. For example, arithmetic requires its arguments to be evaluated:
623623

624-
Prelude> 3 + undefined
624+
ghci> 3 + undefined
625625
*** Exception: Prelude.undefined
626626

627627
This does not contradict laziness — it simply means the *value is now required*. Laziness delays evaluation, but it does not eliminate it.
@@ -914,7 +914,7 @@ T.unpack :: Text -> String
914914
Example:
915915

916916
```
917-
Prelude> import qualified Data.Text as T
917+
ghci> import qualified Data.Text as T
918918

919919
Prelude T> txt = T.pack "my effective text"
920920

@@ -961,14 +961,14 @@ It is commonly used for:
961961
Example:
962962

963963
```
964-
Prelude> import qualified Data.ByteString as B
964+
ghci> import qualified Data.ByteString as B
965965
966-
Prelude> bstr = B.pack [97, 98, 99]
966+
ghci> bstr = B.pack [97, 98, 99]
967967
968-
Prelude> bstr
968+
ghci> bstr
969969
"abc"
970970
971-
Prelude> B.index bstr 2
971+
ghci> B.index bstr 2
972972
99
973973
```
974974

@@ -982,10 +982,10 @@ For ASCII-based text, there is a convenient variant [Data.ByteString.Char8](http
982982
import qualified Data.ByteString.Char8 as C
983983
```
984984
```
985-
Prelude> C.pack "abc"
985+
ghci> C.pack "abc"
986986
"abc"
987987

988-
Prelude> C.index (C.pack "abc") 2
988+
ghci> C.index (C.pack "abc") 2
989989
'c'
990990
```
991991
@@ -1000,7 +1000,7 @@ import qualified Data.Text.Encoding as E
10001000
```
10011001

10021002
```
1003-
Prelude> E.encodeUtf8 (T.pack "život, жизнь, lífið")
1003+
ghci> E.encodeUtf8 (T.pack "život, жизнь, lífið")
10041004
```
10051005

10061006
Encoding makes it explicit:
@@ -1029,16 +1029,16 @@ or in GHCi:
10291029
Now *string literals become polymorphic*:
10301030

10311031
```
1032-
Prelude> :type "abc"
1032+
ghci> :type "abc"
10331033
"abc" :: IsString p => p
10341034
```
10351035

10361036
This allows code like the following, without explicit `pack`:
10371037

10381038
```
1039-
Prelude> import qualified Data.Text as T
1039+
ghci> import qualified Data.Text as T
10401040
1041-
Prelude> T.length "abc"
1041+
ghci> T.length "abc"
10421042
3
10431043
```
10441044

@@ -1054,7 +1054,7 @@ You can always convert between them when needed and sometimes your choice will d
10541054

10551055
## Task assignment
10561056

1057-
For the second assignment, navigate to the `hw03` project and follow the instructions in the `README.md` file there. It will test your skills in branching, local definitions, and working with modules.
1057+
For the assignment, navigate to the `hw03` project and follow the instructions in the `README.md` file there. It will test your skills in branching, local definitions, and working with modules.
10581058

10591059
## Further reading
10601060

0 commit comments

Comments
 (0)