| ... |
... |
@@ -403,7 +403,7 @@ it can be *instantiated* to ``IO a``. For example |
|
403
|
403
|
|
|
404
|
404
|
.. code-block:: none
|
|
405
|
405
|
|
|
406
|
|
- ghci> return True
|
|
|
406
|
+ ghci> pure True
|
|
407
|
407
|
True
|
|
408
|
408
|
|
|
409
|
409
|
Furthermore, GHCi will print the result of the I/O action if (and only
|
| ... |
... |
@@ -419,7 +419,7 @@ For example, remembering that ``putStrLn :: String -> IO ()``: |
|
419
|
419
|
|
|
420
|
420
|
ghci> putStrLn "hello"
|
|
421
|
421
|
hello
|
|
422
|
|
- ghci> do { putStrLn "hello"; return "yes" }
|
|
|
422
|
+ ghci> do { putStrLn "hello"; pure "yes" }
|
|
423
|
423
|
hello
|
|
424
|
424
|
"yes"
|
|
425
|
425
|
|
| ... |
... |
@@ -443,12 +443,12 @@ prompt must be in the ``IO`` monad. |
|
443
|
443
|
|
|
444
|
444
|
.. code-block:: none
|
|
445
|
445
|
|
|
446
|
|
- ghci> x <- return 42
|
|
|
446
|
+ ghci> x <- pure 42
|
|
447
|
447
|
ghci> print x
|
|
448
|
448
|
42
|
|
449
|
449
|
ghci>
|
|
450
|
450
|
|
|
451
|
|
-The statement ``x <- return 42`` means “execute ``return 42`` in the
|
|
|
451
|
+The statement ``x <- pure 42`` means “execute ``pure 42`` in the
|
|
452
|
452
|
``IO`` monad, and bind the result to ``x``\ ”. We can then use ``x`` in
|
|
453
|
453
|
future statements, for example to print it as we did above.
|
|
454
|
454
|
|
| ... |
... |
@@ -2389,7 +2389,7 @@ commonly used commands. |
|
2389
|
2389
|
|
|
2390
|
2390
|
.. code-block:: none
|
|
2391
|
2391
|
|
|
2392
|
|
- ghci> let date _ = Data.Time.getZonedTime >>= print >> return ""
|
|
|
2392
|
+ ghci> let date _ = Data.Time.getZonedTime >>= print >> pure ""
|
|
2393
|
2393
|
ghci> :def date date
|
|
2394
|
2394
|
ghci> :date
|
|
2395
|
2395
|
2017-04-10 12:34:56.93213581 UTC
|
| ... |
... |
@@ -2399,16 +2399,16 @@ commonly used commands. |
|
2399
|
2399
|
|
|
2400
|
2400
|
.. code-block:: none
|
|
2401
|
2401
|
|
|
2402
|
|
- ghci> let mycd d = System.Directory.setCurrentDirectory d >> return ""
|
|
|
2402
|
+ ghci> let mycd d = System.Directory.setCurrentDirectory d >> pure ""
|
|
2403
|
2403
|
ghci> :def mycd mycd
|
|
2404
|
2404
|
ghci> :mycd ..
|
|
2405
|
2405
|
|
|
2406
|
|
- Or I could define a simple way to invoke "``ghc --make Main``"
|
|
|
2406
|
+ Or we could define a simple way to invoke "``ghc --make Main``"
|
|
2407
|
2407
|
in the current directory:
|
|
2408
|
2408
|
|
|
2409
|
2409
|
.. code-block:: none
|
|
2410
|
2410
|
|
|
2411
|
|
- ghci> :def make (\_ -> return ":! ghc --make Main")
|
|
|
2411
|
+ ghci> :def make (\_ -> pure ":! ghc --make Main")
|
|
2412
|
2412
|
|
|
2413
|
2413
|
We can define a command that reads GHCi input from a file. This
|
|
2414
|
2414
|
might be useful for creating a set of bindings that we want to
|
| ... |
... |
@@ -2430,6 +2430,15 @@ commonly used commands. |
|
2430
|
2430
|
a double colon (eg ``::load``).
|
|
2431
|
2431
|
It's not possible to redefine the commands ``:{``, ``:}`` and ``:!``.
|
|
2432
|
2432
|
|
|
|
2433
|
+ For historical reasons, ``:m`` in ghci is shorthand for ``:module``.
|
|
|
2434
|
+ If we want to override that to mean ``:main``, in a way that also
|
|
|
2435
|
+ works when the implicit Prelude is deactivated, we can do it like
|
|
|
2436
|
+ this using ``:def!``:
|
|
|
2437
|
+
|
|
|
2438
|
+ .. code-block:: none
|
|
|
2439
|
+
|
|
|
2440
|
+ ghci> :def! m \_ -> Prelude.pure ":main"
|
|
|
2441
|
+
|
|
2433
|
2442
|
.. ghci-cmd:: :delete; * | ⟨num⟩ ...
|
|
2434
|
2443
|
|
|
2435
|
2444
|
Delete one or more breakpoints by number (use :ghci-cmd:`:show breaks` to
|
| ... |
... |
@@ -2912,7 +2921,7 @@ commonly used commands. |
|
2912
|
2921
|
|
|
2913
|
2922
|
.. code-block:: none
|
|
2914
|
2923
|
|
|
2915
|
|
- *ghci> :def cond \expr -> return (":cmd if (" ++ expr ++ ") then return \"\" else return \":continue\"")
|
|
|
2924
|
+ *ghci> :def cond \expr -> pure (":cmd if (" ++ expr ++ ") then pure \"\" else pure \":continue\"")
|
|
2916
|
2925
|
*ghci> :set stop 0 :cond (x < 3)
|
|
2917
|
2926
|
|
|
2918
|
2927
|
To ignore breakpoints for a specified number of iterations use
|