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
*[The Lambda Calculus for Absolute Dummies (like myself)](http://palmstroem.blogspot.cz/2012/05/lambda-calculus-for-absolute-dummies.html)
14
14
15
-
For FIT CTU students, there are subjects [BI-PPA](https://edux.fit.cvut.cz/courses/BI-PPA) and [MI-PSL](https://edux.fit.cvut.cz/courses/MI-PSL) which also cover basics of lambda calculus and functional programming.
15
+
For FIT CTU students, there are subjects [BI-PPA](https://courses.fit.cvut.cz/BI-PPA/) and [MI-PSL](https://courses.fit.cvut.cz/MI-PSL/) which also cover basics of lambda calculus and functional programming.
*[Stack] = managing Haskell projects, works with [Cabal] for you.
57
57
58
-
:point_right: Please these (or check if installed already) - you can follow instruction on official websites one by one or (better) install [Haskell Platform], which includes all of those and also most common packages.
58
+
:point_right: Please, install these (or check if installed already) - you can follow instruction on official websites one by one or (better) install [Haskell Platform], which includes all of those and also most common packages.
59
59
60
60
### Editors and IDEs
61
61
@@ -72,40 +72,42 @@ Most probably you will need following stuff:
Install those with [Cabal] (by default it will install just for you to your profile, ensure that you have `~/.cabal/bin` in your `PATH`. The installation might take a while - it has a lot of dependencies and needs to build them from Haskell source code. If you want to install something with [Cabal] to all users, use `--global` flag.
75
+
Install those with [Cabal] (by default it will install just for you to your profile, ensure that you have `~/.cabal/bin` in your `PATH`) or with [Stack]. The installation might take a while - it has a lot of dependencies and needs to build them from Haskell source code. If you want to install something with [Cabal] to all users, use `--global` flag.
*[Hackage] = package archive, there are packages which can you install and use standalone or as modules for your projects (similar to PyPI for Python, RubyGems for Ruby, etc.)
87
87
*[Stackage] = package archive, alternative to [Hackage], only stable packages
88
88
89
89
:point_right: Take a look at them...
90
90
91
91
### Haskell, JavaScript and new languages
92
92
93
-
If you like to build (frontend/backend) JavaScript applications you can do that nicely with Haskell. There are multiple options, most known are:
93
+
If you like to build (frontend/backend) JavaScript applications you can do that nicely with Haskell or similar language. There are multiple options, most known are:
94
94
95
95
*[GHCJS]
96
96
*[Haste]
97
97
*[PureScript]
98
-
*[Elm]
98
+
*[Elm] (will be covered in later lectures)
99
99
100
100
This is a nice example of practical usage of Haskell for web projects! It is so much easier (and safer) to write JavaScript in Haskell than just plain JavaScript. Some of those are not just Haskell dialects or libraries but new languages deeply inspired by Haskell. For more information, read about [The JavaScript Problem](https://wiki.haskell.org/The_JavaScript_Problem). We will slightly look at this at the end of this course.
101
101
102
102
## Try to be interactive
103
103
104
-
Now you should have [GHC] installed (and others as well, but we won't need an editor for this time), you can test it out with the following command.
104
+
Now you should have [GHC] installed from package or via Stack (and others as well, but we won't need an editor for this time), you can test it out with the following command.
105
105
106
-
```
106
+
```console
107
107
% ghc --version
108
108
The Glorious Glasgow Haskell Compilation System, version 8.0.2
109
+
% stack exec -- ghc --version
110
+
The Glorious Glasgow Haskell Compilation System, version 8.0.2
109
111
```
110
112
111
113
First, let's try the interactive environment and evaluate some basic expression in Haskell for the first time.
@@ -244,7 +246,7 @@ Prelude> 5 `mod` 3
244
246
2
245
247
```
246
248
247
-
### Giving name to expression
249
+
### Giving a name to an expression
248
250
249
251
In GHCi you can name an expression with `let` and assignment.
250
252
@@ -359,7 +361,7 @@ main = putStrLn "Hello, world!"
359
361
360
362
Now use `ghc` compiler to compile the file:
361
363
362
-
```
364
+
```console
363
365
% ghc 01_hw.hs
364
366
[1 of 1] Compiling Main ( 01_hw.hs, 01_hw.o )
365
367
Linking 01_hw ...
@@ -374,7 +376,7 @@ You can see some similar output as when you were loading a file in GHCi just her
374
376
375
377
And you can run the executable:
376
378
377
-
```
379
+
```console
378
380
% ./01_hw
379
381
Hello, world!
380
382
```
@@ -399,9 +401,9 @@ main = do
399
401
putStrLn (greet name)
400
402
```
401
403
402
-
Now how to make it work together? Do you know `Makefile`s from `C/C++`? Don't worry... GHC is a great tool and does such painful work for you (reads imports and looking up the files - you just need to have good naming of modules/files):
404
+
Now how to make it work together? Do you know `Makefile` (for example, from `C/C++`)? Don't worry... GHC is a great tool and does such painful work for you (reads imports and looking up the files - you just need to have a standard naming of modules/files):
403
405
404
-
```
406
+
```console
405
407
% ghc --make Main.hs
406
408
[1 of 2] Compiling HWLib ( HWLib.hs, HWLib.o )
407
409
[2 of 2] Compiling Main ( Main.hs, Main.o )
@@ -418,37 +420,48 @@ Compiling application made from multiple source codes is not so complicated in t
418
420
419
421
Let's do the *Hello, world!* app with [Stack]. First, verify that you have it installed.
420
422
421
-
```
423
+
```console
422
424
% stack --version
423
-
Version 1.4.0, Git revision e714f1dd3fade19496d91bd6a017e435a96a6bcd (4640 commits) x86_64 hpack-0.17.0
425
+
Version 1.9.3, Git revision 40cf7b37526b86d1676da82167ea8758a854953b (6211 commits) x86_64 hpack-0.31.1
424
426
```
425
427
426
428
Then you can create a new project with default template:
427
429
428
-
```
430
+
```console
429
431
% stack new HelloWorld
430
432
Downloading template "new-template" to create project "HelloWorld" in HelloWorld/ ...
431
433
432
-
...
434
+
The following parameters were needed by the template but not provided: author-name
435
+
You can provide them in /home/user/.stack/config.yaml, like this:
436
+
templates:
437
+
params:
438
+
author-name: value
439
+
Or you can pass each one as parameters like this:
440
+
stack new HelloWorld new-template -p "author-name:value"
441
+
442
+
443
+
The following parameters were needed by the template but not provided: author-email, author-name, category, copyright, github-username
444
+
You can provide them in /home/user/.stack/config.yaml, like this:
Initialising configuration using resolver: lts-9.11
461
+
* Matches lts-13.8
462
+
463
+
Selected resolver: lts-13.8
464
+
Initialising configuration using resolver: lts-13.8
452
465
Total number of user packages considered: 1
453
466
Writing configuration to file: HelloWorld/stack.yaml
454
467
All done.
@@ -481,15 +494,15 @@ main = do
481
494
482
495
Now you don't use GHC directly, but call it via `stack build`:
483
496
484
-
```
497
+
```console
485
498
% stack build
486
499
No compiler found, expected minor version match with ghc-8.0.2 (x86_64) (based on resolver setting in /home/user/.stack/global-project/stack.yaml).
487
500
To install the correct GHC into /home/user/.stack/programs/x86_64-linux/, try running "stack setup" or use the "--install-ghc" flag. To use your system GHC installation, run "stack config set system-ghc --global true", or use the "--system-ghc" flag.
488
501
```
489
502
490
503
As you see `stack` doesn't want to use system-wide installation of `ghc` but local instead by default. Just run `stack setup` so `stack` will prepare local `ghc` (it will take some time) and then try to build.
491
504
492
-
```
505
+
```console
493
506
% stack setup
494
507
Preparing to install GHC to an isolated location.
495
508
This will not interfere with any system-level installation.
@@ -507,35 +520,38 @@ Using cabal packages:
507
520
508
521
Selecting the best among 11 snapshots...
509
522
510
-
* Matches lts-9.11
523
+
* Matches lts-13.8
511
524
512
-
Selected resolver: lts-9.11
525
+
Selected resolver: lts-13.8
513
526
Initialising configuration using resolver: lts-9.11
Installing library in /home/user/Projects/MI-AFP/tests/HelloWorld/.stack-work/install/x86_64-linux-tinfo6/lts-13.8/8.6.3/lib/x86_64-linux-ghc-8.6.3/HelloWorld-0.1.0.0-8b39YCi0nmn4QsoDKix2j8
547
+
Installing executable HelloWorld-exe in /home/user/Projects/MI-AFP/tests/HelloWorld/.stack-work/install/x86_64-linux-tinfo6/lts-13.8/8.6.3/bin
548
+
Registering library for HelloWorld-0.1.0.0..
549
+
stack build 6.16s user 0.94s system 96% cpu 7.329 total
534
550
```
535
551
536
552
Everything ended up OK and you are finally able to run the application (`HelloWorld-exe` is defined in `package.yaml`, thus also `HelloWorld.cabal`, and you may change it):
537
553
538
-
```
554
+
```console
539
555
% stack exec HelloWorld-exe
540
556
Enter your name:
541
557
Marek
@@ -544,18 +560,18 @@ Hello, Marek!
544
560
545
561
For debugging you can run `ghci` with project preloaded:
546
562
547
-
```
563
+
```console
548
564
% stack ghci
565
+
Using main module: 1. Package `HelloWorld' component exe:HelloWorld-exe with main-is file: /home/user/Projects/MI-AFP/tests/HelloWorld/app/Main.hs
549
566
The following GHC options are incompatible with GHCi and have not been passed to it: -threaded
550
567
Configuring GHCi with the following packages: HelloWorld
551
-
Using main module: 1. Package `HelloWorld' component exe:HelloWorld-exe with main-is file: /home/.../HelloWorld/app/Main.hs
552
-
GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help
553
-
[1 of 1] Compiling Lib ( /home/.../HelloWorld/src/Lib.hs, interpreted )
554
-
Ok, modules loaded: Lib.
555
-
[2 of 2] Compiling Main ( /home/.../HelloWorld/app/Main.hs, interpreted )
556
-
Ok, modules loaded: Lib, Main.
557
-
Loaded GHCi configuration from /tmp/ghci18580/ghci-script
558
-
*Main Lib> :browse
568
+
GHCi, version 8.6.3: http://www.haskell.org/ghc/ :? for help
569
+
[1 of 2] Compiling Lib ( /home/user/Projects/MI-AFP/tests/HelloWorld/src/Lib.hs, interpreted )
570
+
[2 of 2] Compiling Main ( /home/user/Projects/MI-AFP/tests/HelloWorld/app/Main.hs, interpreted )
571
+
Ok, two modules loaded.
572
+
Loaded GHCi configuration from /tmp/haskell-stack-ghci/3b07e5cf/ghci-script
573
+
*Main Lib>
574
+
:browse
559
575
main :: IO ()
560
576
*Main Lib> :browse Lib
561
577
greet :: String -> String
@@ -567,7 +583,7 @@ greet :: String -> String
567
583
568
584
You might have noticed that [Stack] uses `package.yaml` to generate `.cabal` and there is some `stack.yaml`. It also somehow takes care of the needed dependencies. Let's say you need to your collection of type Set. Of course, you could implement it on your own, but reinventing the wheel is unnecessary! Use `Data.Set` which is already here (we will cover details about this and other data structures in Haskell in the future).
569
585
570
-
If you look up `Data.Set` ([Hoogle], [Hayoo!] or [Hackage]), you will find out that it is in package `containers` licensed under BSD with maintainer email [email protected] (see [here](http://hackage.haskell.org/package/containers-0.5.11.0/docs/Data-Set.html)). If you now try to do this in your `Lib.hs`:
586
+
If you look up `Data.Set` ([Hoogle], [Stackage] or [Hackage]), you will find out that it is in package `containers` licensed under BSD with maintainer email [email protected] (see [here](http://hackage.haskell.org/package/containers-0.5.11.0/docs/Data-Set.html)). If you now try to do this in your `Lib.hs`:
After trying to build with `stack build` you should get this error stating that it could not find module `Data.Set`:
579
595
580
-
```
596
+
```console
581
597
/home/.../HelloWorld/src/Lib.hs:5:1: error:
582
598
Could not find module ‘Data.Set’
583
599
Perhaps you meant Data.Int (from base-4.10.1.0)
@@ -616,7 +632,7 @@ Further, [Stack] also provides [dependency visualization](https://docs.haskellst
616
632
617
633
To test out the workflow check the dummy homework [MI-AFP/hw00](https://github.com/MI-AFP/hw00) where you will learn how you should get, complete, check, and submit homework (especially useful if you are not familiar with [GitHub] and [Travis CI]). By working on such homework, you might also learn new things which you encounter in tests and skeletons.
618
634
619
-
For your first assignment, visit [MI-AFP/hw01](https://github.com/MI-AFP/hw01). The task consists of writing simple expressions, looking up information with [Hoogle], [Hayoo!] and/or GHCi, and working with dependencies of project.
635
+
For your first assignment, visit [MI-AFP/hw01](https://github.com/MI-AFP/hw01). The task consists of writing simple expressions, looking up information with [Hoogle], [Stackage], [Hackage] and/or GHCi, and working with dependencies of project.
620
636
621
637
## Further reading
622
638
@@ -638,7 +654,6 @@ For your first assignment, visit [MI-AFP/hw01](https://github.com/MI-AFP/hw01).
0 commit comments