-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathLessons-Lesson01.html
More file actions
21 lines (21 loc) · 6.34 KB
/
Lessons-Lesson01.html
File metadata and controls
21 lines (21 loc) · 6.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1" /><title>Lessons.Lesson01</title><link href="linuwial.css" rel="stylesheet" type="text/css" title="Linuwial" /><link rel="stylesheet" type="text/css" href="quick-jump.css" /><link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=PT+Sans:400,400i,700" /><script src="haddock-bundle.min.js" async="async" type="text/javascript"></script><script type="text/x-mathjax-config">MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script></head><body><div id="package-header"><span class="caption empty"> </span><ul class="links" id="page-menu"><li><a href="src/Lessons.Lesson01.html">Source</a></li><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul></div><div id="content"><div id="module-header"><table class="info"><tr><th>Safe Haskell</th><td>Safe-Inferred</td></tr></table><p class="caption">Lessons.Lesson01</p></div><div id="description"><p class="caption">Description</p><div class="doc"><p>Notes taken by Ugnė Pacevičiūtė </p><p>Module is a unit of compilation. A module can export values, functions,..
so they become accessible from other modules.</p><p>Core thing to remember: all values (not variables) are immutable!</p></div></div><div id="synopsis"><details id="syn"><summary>Synopsis</summary><ul class="details-toggle" data-details-id="syn"><li class="src short"><a href="#v:i">i</a> :: Integer</li><li class="src short"><a href="#v:ii">ii</a> :: Int</li><li class="src short"><a href="#v:c">c</a> :: Char</li><li class="src short"><a href="#v:s">s</a> :: String</li><li class="src short"><a href="#v:b">b</a> :: Bool</li><li class="src short"><a href="#v:f">f</a> :: Integer -> Bool</li><li class="src short"><a href="#v:add">add</a> :: Integer -> Integer -> Integer</li><li class="src short"><a href="#v:il">il</a> :: [Integer]</li><li class="src short"><a href="#v:cl">cl</a> :: [Char]</li></ul></details></div><div id="interface"><h1>Documentation</h1><div class="top"><p class="src"><a id="v:i" class="def">i</a> :: Integer <a href="src/Lessons.Lesson01.html#i" class="link">Source</a> <a href="#v:i" class="selflink">#</a></p><div class="doc"><p>First let's declare some values.
In Integer is unbounded (or endless) integer value which
does not depend on your computer's architecture so never overflows.
The first line is a signature (`::` is a delimiter between a name and a type).
The second line is a body.</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>i + i == 84
</code></strong>True
</pre></div></div><div class="top"><p class="src"><a id="v:ii" class="def">ii</a> :: Int <a href="src/Lessons.Lesson01.html#ii" class="link">Source</a> <a href="#v:ii" class="selflink">#</a></p><div class="doc"><p>An Int represents an integer which size respects your computer's architecture.
Might overflow.</p></div></div><div class="top"><p class="src"><a id="v:c" class="def">c</a> :: Char <a href="src/Lessons.Lesson01.html#c" class="link">Source</a> <a href="#v:c" class="selflink">#</a></p><div class="doc"><p>A single character</p></div></div><div class="top"><p class="src"><a id="v:s" class="def">s</a> :: String <a href="src/Lessons.Lesson01.html#s" class="link">Source</a> <a href="#v:s" class="selflink">#</a></p><div class="doc"><p>A String (technically, a list of Chars)</p></div></div><div class="top"><p class="src"><a id="v:b" class="def">b</a> :: Bool <a href="src/Lessons.Lesson01.html#b" class="link">Source</a> <a href="#v:b" class="selflink">#</a></p><div class="doc"><p>A Boolean, might be <code>True</code> or <code>False</code></p></div></div><div class="top"><p class="src"><a id="v:f" class="def">f</a> :: Integer -> Bool <a href="src/Lessons.Lesson01.html#f" class="link">Source</a> <a href="#v:f" class="selflink">#</a></p><div class="doc"><p>So, let's assume we know how to declare values, but what about functions?
Functions and values are declared in a similar way, here we have a function
which takes an Integer as a parameter and returns a Bool.</p><p>Values are functions which do not take any arguments!</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>f 23
</code></strong>True
</pre><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>f 19
</code></strong>False
</pre></div></div><div class="top"><p class="src"><a id="v:add" class="def">add</a> :: Integer -> Integer -> Integer <a href="src/Lessons.Lesson01.html#add" class="link">Source</a> <a href="#v:add" class="selflink">#</a></p><div class="doc"><p>This is a bit more sophisticated case: function takes two arguments.</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>add 20 22
</code></strong>42
</pre><p>But what is we pass less arguments than needed? You get a function as a result!</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>:t add 20
</code></strong>add 20 :: Integer -> Integer
</pre><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>:t add
</code></strong>add :: Integer -> Integer -> Integer
</pre><p>This technique is called <a href="https://en.wikipedia.org/wiki/Currying">Currying</a></p></div></div><div class="top"><p class="src"><a id="v:il" class="def">il</a> :: [Integer] <a href="src/Lessons.Lesson01.html#il" class="link">Source</a> <a href="#v:il" class="selflink">#</a></p><div class="doc"><p>Another built-in type: a list. It has a special syntax</p></div></div><div class="top"><p class="src"><a id="v:cl" class="def">cl</a> :: [Char] <a href="src/Lessons.Lesson01.html#cl" class="link">Source</a> <a href="#v:cl" class="selflink">#</a></p><div class="doc"><p>And, as it was mentioned a bit earlier, a String is a list of Chars.</p></div></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.29.2</p></div></body></html>