Difference between revisions of "Functional programming"

From Marek Běhálek Wiki
Jump to navigation Jump to search
Line 23: Line 23:
  
 
== Software == <!--T:15-->
 
== Software == <!--T:15-->
In our lectures, we will be using [https://www.haskell.org/downloads/#platform Haskell Platform] with [https://code.visualstudio.com/ Visual Studio Code]. For VS Code, we will be using two extensions:
+
In our lectures, we will be using [https://www.haskell.org/downloads/#platform Haskell Platform] with [https://code.visualstudio.com/ Visual Studio Code]. For VS Code, we will be using an extension:
*[https://marketplace.visualstudio.com/items?itemName=Vans.haskero Haskero]
+
*[https://marketplace.visualstudio.com/items?itemName=haskell.haskell Haskell]
*[https://marketplace.visualstudio.com/items?itemName=phoityne.phoityne-vscode Haskell GHCi Debug Adapter Phoityne]
 
  
=== Installation guide Windows (single user) === <!--T:16-->
+
More information about various options for work environments can be found: [[FP_installation_guide | Installation Guide]]
  
<!--T:17-->
 
# Download and install Haskell platform from [https://www.haskell.org/platform/windows.html https://www.haskell.org/platform/windows.html]
 
#* Use default paths. Installer adds to system variable <code>PATH</code> a path to executable <code>stack.exe</code>.
 
# Download and install VS Code [https://code.visualstudio.com/#alt-downloads https://code.visualstudio.com/#alt-downloads]
 
# Open <code>cmd</code> and type:<pre class="bash">stack install intero phoityne-vscode haskell-dap --system-ghc</pre>
 
# Open file <code>c:\sr\config.yaml</code> and add a line <pre>system-ghc : true</pre>
 
#* Attribute <code>--system-ghc</code> is optional and redundant to previous step (it is the same setting, but global).
 
# Open VS Code and install extensions:
 
#* Haskero
 
#* Haskell GHCi Debug Adapter Phoityne
 
 
=== Installation guide Windows (all users) === <!--T:18-->
 
This guide assumes, that there is on user, that prepares the development environment for other user.
 
<ol>
 
<li>Download and install Haskell platform from [https://www.haskell.org/platform/windows.html https://www.haskell.org/platform/windows.html] </li>
 
<li>* For <code>stack</code>, use a path accessible to all user (for example <code>c:\stack</code>). Installer adds to user variable <code>PATH</code> a path to executable <code>stack.exe</code>, and adds a new user variable <code>STACK_ROOT</code>. Move these values from user variables to system variables.
 
</li>
 
<li>Download and install VS Code [https://code.visualstudio.com/#alt-downloads https://code.visualstudio.com/#alt-downloads]. Use the system installer.</li>
 
<li>Open <code>cmd</code> and type:<pre class="bash">stack install intero phoityne-vscode haskell-dap --system-ghc</pre>
 
* It will generate some executable files to default location: <code>c:\Users\ -- YOUR NAME -- \AppData\Roaming\local\bin\</code> move them to the directory with <code>stack.exe</code>.
 
</li>
 
<li>Open file <code>c:\sr\config.yaml</code> and add lines:
 
<pre>
 
system-ghc : true
 
skip-msys : true
 
</pre>
 
These settings save time and space on disk (it will not install GHC while installing packages and [https://www.msys2.org/ MSYS2] for every user).
 
</li>
 
<li> Open VS Code and install extensions:
 
* Haskero
 
* Haskell GHCi Debug Adapter Phoityne
 
</li>
 
</ol>
 
 
=== Installation guide Ubuntu (single users) === <!--T:21-->
 
<ol>
 
<li>Perform following commands:
 
<pre class="bash">
 
sudo apt-get install haskell-platform
 
sudo apt-get install haskell-stack
 
sudo snap install code --classic
 
</pre>
 
* ''Optional step'' - Right now (August, 2019) Haskell Platform from Ubuntu repositories contains GHC 8.4.4. Stack current default resolver is lts-14.00. It requires GHC version 8.6.5. It will automatically download this version. To save disk space, you can generate stack global config (for example <code>stack path</code>) and change the global resolver in file <code>~/.stack/global-project/stack.yaml</code> to <code>lts-12.15</code>. Then open file <code>~/.stack/config.yaml</code> and add lines:
 
<pre>
 
system-ghc : true
 
skip-ghc-check: true
 
</pre>
 
</li>
 
<li> Continue with installation of required packages:
 
<pre class="bash">
 
stack install intero phoityne-vscode haskell-dap
 
</pre></li>
 
<li> Open VS Code and install extensions:
 
* Haskero
 
* Haskell GHCi Debug Adapter Phoityne
 
</li>
 
</ol>
 
 
=== Installation guide Ubuntu (all users) === <!--T:19-->
 
<ol>
 
<li>
 
Perform following commands:
 
<pre class="bash">
 
sudo apt-get install haskell-platform
 
sudo apt-get install haskell-stack
 
sudo snap install code --classic
 
</pre>
 
</li>
 
<li>Create a directory that will be a stack root, it should be readable by all users (for example <code>/opt/stack</code>).</li>
 
<li>Create a file <code>/etc/profile.d/stack.sh</code> with following line:<CODE>export STACK_ROOT=</CODE>''your stack root directory''</li>
 
<li>Create a file <code>/etc/stack/config.yaml</code> with following lines:
 
<pre>
 
skip-ghc-check: true
 
system-ghc: true
 
allow-different-user: true
 
</pre>
 
</li>
 
<li>Generate stack global config (for example <code>stack path</code>) and change the global resolver in file <code>$STACK_ROOT/global-project/stack.yaml</code> to
 
*<code>lts-12.15</code> for Ubuntu 19.04 (ghc 8.4.4)
 
*<code>lts-8.0</code> for Ubuntu 18.04 (ghc 8.0.2)</li>
 
<li> Continue with installation of required packages:
 
<pre class="bash">
 
stack install intero phoityne-vscode haskell-dap
 
</pre></li>
 
<li>It will produce some executable files to <code>~/.local/bin</code> copy them to: <code>/usr/local/bin</code> (or other ''search when executing'' location).
 
</li>
 
<li> Open VS Code and install extensions:
 
* Haskero
 
* Haskell GHCi Debug Adapter Phoityne
 
</translate>
 
<pre class="bash">code --install-extension phoityne.phoityne-vscode
 
code --install-extension Vans.haskero</pre>
 
</li>
 
</ol>
 
<translate>
 
 
== Presentations == <!--T:11-->
 
== Presentations == <!--T:11-->
 
</translate>
 
</translate>

Revision as of 13:30, 20 August 2020

Basic introduction

The course introduces the functional style of programming. It covers basic properties of the functional programming like: the side effect-free programming, functions as first-class values, high-order functions, recursion, pattern matching, or function closures. Also, course introduces selected data structures like a list and a tree and a functional style of working with these structures. As a programming language, Haskell will be used. It is a pure functional, statically typed, lazy evaluated language.

Subject aims expressed by acquired skills and competences

The basic outcome of this course will be the ability to write simple algorithms using a functional style of programming. More precisely, students will understand recursion and recursive data structures, they will be able to use high-order functions, and they will be able to define functions using the pattern matching. They will be able to use functional encapsulation mechanisms such as closures and modular interfaces and correctly reason about variables and lexical scope in programs. On practical level, they will be able to write these basic algorithms in programming language Haskell. Moreover, they will be able to recognize functional style of programming, they will understand advantages and disadvantages of this style of programming and they will be able to compare this style of programming with other approaches like imperative or object-oriented programming.

Recommended literature

  • Lipovaca M.:Learn You a Haskell for Great Good!: A Beginner's Guide (1st ed.). No Starch Press, San Francisco, CA, USA, 2011 - for free at: http://learnyouahaskell.com/
  • Thompson S.: The Haskell: The Craft of Functional Programming (3nd ed.). Addison-Wesley Professional, October 2, 2011, ISBN-10: 0201882957.

Way of continuous check of knowledge in the course of semester

During the exercises, students will be programming assigned tasks. The results of these tasks will be the crucial part of the final evaluation. Additionally, two smaller projects will be given.

Software

In our lectures, we will be using Haskell Platform with Visual Studio Code. For VS Code, we will be using an extension:

More information about various options for work environments can be found: Installation Guide

Presentations

Presentations used in our lectures:

Introduction to FPR

Basics of functional Programming

Introduction to advanced topics of functional programming

Schedule:


Laboratories

Solutions to tasks form laboratories: Solution

Cheat sheet containing basic functions in PDF

Homework

Combine study