-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathLessons-Lesson03.html
More file actions
54 lines (54 loc) · 22.6 KB
/
Lessons-Lesson03.html
File metadata and controls
54 lines (54 loc) · 22.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!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.Lesson03</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.Lesson03.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.Lesson03</p></div><div id="description"><p class="caption">Description</p><div class="doc"><p>Notes taken by Ugnė Pacevičiūtė </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:sumOfInts">sumOfInts</a> :: [Int] -> Int</li><li class="src short"><a href="#v:sumOfInts-39-">sumOfInts'</a> :: [Int] -> Int</li><li class="src short"><span class="keyword">data</span> <a href="#t:Dumpable">Dumpable</a> = <a href="#v:Examples">Examples</a></li><li class="src short"><span class="keyword">data</span> <a href="#t:Command">Command</a><ul class="subs"><li>= <a href="#v:Dump">Dump</a> <a href="Lessons-Lesson03.html#t:Dumpable" title="Lessons.Lesson03">Dumpable</a></li><li>| <a href="#v:Sum">Sum</a> [Int]</li></ul></li><li class="src short"><span class="keyword">class</span> <a href="#t:FuzzyAdd">FuzzyAdd</a> a <span class="keyword">where</span><ul class="subs"><li><a href="#v:-126--43--126-">(~+~)</a> :: a -> a -> a</li></ul></li><li class="src short"><a href="#v:a1">a1</a> :: Integer</li><li class="src short"><a href="#v:a2">a2</a> :: Integer</li><li class="src short"><span class="keyword">data</span> <a href="#t:FireExtinguisher">FireExtinguisher</a> = <a href="#v:FireExtinguisher">FireExtinguisher</a> {<ul class="subs"><li><a href="#v:capacity">capacity</a> :: Integer</li><li><a href="#v:feType">feType</a> :: <a href="Lessons-Lesson02.html#t:FEType" title="Lessons.Lesson02">FEType</a></li></ul>}</li><li class="src short"><a href="#v:fe">fe</a> :: <a href="Lessons-Lesson03.html#t:FireExtinguisher" title="Lessons.Lesson03">FireExtinguisher</a></li><li class="src short"><a href="#v:fe2">fe2</a> :: <a href="Lessons-Lesson03.html#t:FireExtinguisher" title="Lessons.Lesson03">FireExtinguisher</a></li><li class="src short"><a href="#v:cpcty">cpcty</a> :: <a href="Lessons-Lesson03.html#t:FireExtinguisher" title="Lessons.Lesson03">FireExtinguisher</a> -> Integer</li><li class="src short"><span class="keyword">data</span> <a href="#t:Bucket">Bucket</a> = <a href="#v:Bucket">Bucket</a> {<ul class="subs"><li><a href="#v:bucketCapacity">bucketCapacity</a> :: Integer</li></ul>}</li><li class="src short"><a href="#v:safeHead">safeHead</a> :: [a] -> Maybe a</li><li class="src short"><a href="#v:safeHeadDefault">safeHeadDefault</a> :: [a] -> a -> a</li></ul></details></div><div id="interface"><h1>Documentation</h1><div class="top"><p class="src"><a id="v:sumOfInts" class="def">sumOfInts</a> :: [Int] -> Int <a href="src/Lessons.Lesson03.html#sumOfInts" class="link">Source</a> <a href="#v:sumOfInts" class="selflink">#</a></p><div class="doc"><p>We do not have loops in Haskell, because loops require a
mutable state (e.g. a counter), so we use recursion!
This function sums all integers in a given list.
If the list is empty, it returns 0 as the base case.
Otherwise, it takes the first element (the head) and adds it to the result of summing the rest of the list (the tail).</p></div></div><div class="top"><p class="src"><a id="v:sumOfInts-39-" class="def">sumOfInts'</a> :: [Int] -> Int <a href="src/Lessons.Lesson03.html#sumOfInts%27" class="link">Source</a> <a href="#v:sumOfInts-39-" class="selflink">#</a></p><div class="doc"><p>This function also recursively sums all integers in a given list.
But it has an advantage: instead of accumulating of intemediate results
(needed for + function) in stack, you can accumulate these values in a
dedicated argument, usually called "accumulator". This approach is called
"tail recursion" and modern compiles are smart enough to identify this
technic and optimize it (rewrite it with a machine code loop) so no stack
at all is used.</p></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a id="t:Dumpable" class="def">Dumpable</a> <a href="src/Lessons.Lesson03.html#Dumpable" class="link">Source</a> <a href="#t:Dumpable" class="selflink">#</a></p><div class="doc"><p>In Haskell, a typeclass works similarly to an interface in Java.</p><p>The <code><a href="Lessons-Lesson03.html#t:Command" title="Lessons.Lesson03">Command</a></code> type is an example of an Algebraic Data Type (ADT).
It represents a set of possible "commands" that a program might handle.</p><p>The left-hand side (<code><a href="Lessons-Lesson03.html#t:Command" title="Lessons.Lesson03">Command</a></code>) defines the type name.
The right-hand side lists the constructors (<code><a href="Lessons-Lesson03.html#v:Dump" title="Lessons.Lesson03">Dump</a></code> and <code><a href="Lessons-Lesson03.html#v:Sum" title="Lessons.Lesson03">Sum</a></code>).</p><p>Each constructor defines a different *form* that a <code><a href="Lessons-Lesson03.html#t:Command" title="Lessons.Lesson03">Command</a></code> value can take:
<code><a href="Lessons-Lesson03.html#v:Dump" title="Lessons.Lesson03">Dump</a></code> wraps a <code><a href="Lessons-Lesson03.html#t:Dumpable" title="Lessons.Lesson03">Dumpable</a></code> value.
<code><a href="Lessons-Lesson03.html#v:Sum" title="Lessons.Lesson03">Sum</a></code> wraps a list of integers that can be processed.</p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a id="v:Examples" class="def">Examples</a></td><td class="doc empty"> </td></tr></table></div><div class="subs instances"><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Dumpable">Instances</h4><details id="i:Dumpable" open="open"><summary class="hide-when-js-enabled">Instances details</summary><table><tr><td class="src clearfix"><span class="inst-left"><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Dumpable:Show:1"></span> Show <a href="Lessons-Lesson03.html#t:Dumpable" title="Lessons.Lesson03">Dumpable</a></span> <a href="src/Lessons.Lesson03.html#line-51" class="link">Source</a> <a href="#t:Dumpable" class="selflink">#</a></td><td class="doc"><p>This instance tells Haskell how to display values of type <code><a href="Lessons-Lesson03.html#t:Dumpable" title="Lessons.Lesson03">Dumpable</a></code>
when they are converted to a string using the <code>show</code> function.
In this example, we have only one constructor, <code><a href="Lessons-Lesson03.html#v:Examples" title="Lessons.Lesson03">Examples</a></code>, which
will simply be displayed as the word "examples".
Normally, Haskell can automatically create a default implementation
when we write 'deriving Show', but here we define our own for learning purposes.</p></td></tr><tr><td colspan="2"><details id="i:id:Dumpable:Show:1"><summary class="hide-when-js-enabled">Instance details</summary><p>Defined in <a href="Lessons-Lesson03.html">Lessons.Lesson03</a></p> <div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:showsPrec">showsPrec</a> :: Int -> <a href="Lessons-Lesson03.html#t:Dumpable" title="Lessons.Lesson03">Dumpable</a> -> ShowS</p><p class="src"><a href="#v:show">show</a> :: <a href="Lessons-Lesson03.html#t:Dumpable" title="Lessons.Lesson03">Dumpable</a> -> String</p><p class="src"><a href="#v:showList">showList</a> :: [<a href="Lessons-Lesson03.html#t:Dumpable" title="Lessons.Lesson03">Dumpable</a>] -> ShowS</p></div></details></td></tr></table></details></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a id="t:Command" class="def">Command</a> <a href="src/Lessons.Lesson03.html#Command" class="link">Source</a> <a href="#t:Command" class="selflink">#</a></p><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a id="v:Dump" class="def">Dump</a> <a href="Lessons-Lesson03.html#t:Dumpable" title="Lessons.Lesson03">Dumpable</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a id="v:Sum" class="def">Sum</a> [Int]</td><td class="doc empty"> </td></tr></table></div><div class="subs instances"><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Command">Instances</h4><details id="i:Command" open="open"><summary class="hide-when-js-enabled">Instances details</summary><table><tr><td class="src clearfix"><span class="inst-left"><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Command:Show:1"></span> Show <a href="Lessons-Lesson03.html#t:Command" title="Lessons.Lesson03">Command</a></span> <a href="src/Lessons.Lesson03.html#line-60" class="link">Source</a> <a href="#t:Command" class="selflink">#</a></td><td class="doc"><p>Here we define a custom <code>Show</code> instance for the <code><a href="Lessons-Lesson03.html#t:Command" title="Lessons.Lesson03">Command</a></code> type.
We want each command to be represented as a descriptive string.
If the command is <code><a href="Lessons-Lesson03.html#v:Dump" title="Lessons.Lesson03">Dump</a></code>, it will print as "dump " followed by
whatever the inner <code><a href="Lessons-Lesson03.html#t:Dumpable" title="Lessons.Lesson03">Dumpable</a></code> value looks like.
If it is 'Sum is', it will print as "sum_of " followed by the list of numbers.</p></td></tr><tr><td colspan="2"><details id="i:id:Command:Show:1"><summary class="hide-when-js-enabled">Instance details</summary><p>Defined in <a href="Lessons-Lesson03.html">Lessons.Lesson03</a></p> <div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:showsPrec">showsPrec</a> :: Int -> <a href="Lessons-Lesson03.html#t:Command" title="Lessons.Lesson03">Command</a> -> ShowS</p><p class="src"><a href="#v:show">show</a> :: <a href="Lessons-Lesson03.html#t:Command" title="Lessons.Lesson03">Command</a> -> String</p><p class="src"><a href="#v:showList">showList</a> :: [<a href="Lessons-Lesson03.html#t:Command" title="Lessons.Lesson03">Command</a>] -> ShowS</p></div></details></td></tr></table></details></div></div><div class="top"><p class="src"><span class="keyword">class</span> <a id="t:FuzzyAdd" class="def">FuzzyAdd</a> a <span class="keyword">where</span> <a href="src/Lessons.Lesson03.html#FuzzyAdd" class="link">Source</a> <a href="#t:FuzzyAdd" class="selflink">#</a></p><div class="doc"><p>The <code><a href="Lessons-Lesson03.html#t:FuzzyAdd" title="Lessons.Lesson03">FuzzyAdd</a></code> typeclass represents a group of types that can be
combined using an “fuzzy” addition operation.
The operator (~+~) defines the behavior for this custom kind of addition.</p></div><div class="subs methods"><p class="caption">Methods</p><p class="src"><a id="v:-126--43--126-" class="def">(~+~)</a> :: a -> a -> a <a href="src/Lessons.Lesson03.html#~%2B~" class="link">Source</a> <a href="#v:-126--43--126-" class="selflink">#</a></p></div><div class="subs instances"><h4 class="instances details-toggle-control details-toggle" data-details-id="i:FuzzyAdd">Instances</h4><details id="i:FuzzyAdd" open="open"><summary class="hide-when-js-enabled">Instances details</summary><table><tr><td class="src clearfix"><span class="inst-left"><span class="instance details-toggle-control details-toggle" data-details-id="i:ic:FuzzyAdd:FuzzyAdd:1"></span> <a href="Lessons-Lesson03.html#t:FuzzyAdd" title="Lessons.Lesson03">FuzzyAdd</a> Integer</span> <a href="src/Lessons.Lesson03.html#line-75" class="link">Source</a> <a href="#t:FuzzyAdd" class="selflink">#</a></td><td class="doc"><p>This instance defines how <code><a href="Lessons-Lesson03.html#t:FuzzyAdd" title="Lessons.Lesson03">FuzzyAdd</a></code> works for integers.
Instead of performing a normal sum, it adds two numbersa
and then subtracts one. This is just an illustrative example
showing how we can redefine arithmetic operators in flexible ways.</p></td></tr><tr><td colspan="2"><details id="i:ic:FuzzyAdd:FuzzyAdd:1"><summary class="hide-when-js-enabled">Instance details</summary><p>Defined in <a href="Lessons-Lesson03.html">Lessons.Lesson03</a></p> <div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:-126--43--126-">(~+~)</a> :: Integer -> Integer -> Integer <a href="src/Lessons.Lesson03.html#~%2B~" class="link">Source</a> <a href="#v:-126--43--126-" class="selflink">#</a></p></div></details></td></tr></table></details></div></div><div class="top"><p class="src"><a id="v:a1" class="def">a1</a> :: Integer <a href="src/Lessons.Lesson03.html#a1" class="link">Source</a> <a href="#v:a1" class="selflink">#</a></p></div><div class="top"><p class="src"><a id="v:a2" class="def">a2</a> :: Integer <a href="src/Lessons.Lesson03.html#a2" class="link">Source</a> <a href="#v:a2" class="selflink">#</a></p><div class="doc"><p>FuzzyAdd use case.</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>a1 ~+~ a2
</code></strong>42
</pre></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a id="t:FireExtinguisher" class="def">FireExtinguisher</a> <a href="src/Lessons.Lesson03.html#FireExtinguisher" class="link">Source</a> <a href="#t:FireExtinguisher" class="selflink">#</a></p><div class="doc"><p>Records are usual ADTs which allow to name fields.
The <code><a href="Lessons-Lesson03.html#t:FireExtinguisher" title="Lessons.Lesson03">FireExtinguisher</a></code> type represents a simple data structure
describing a fire extinguisher. Each extinguisher has a capacity
and a type (<code><a href="Lessons-Lesson02.html#t:FEType" title="Lessons.Lesson02">FEType</a></code>), which is imported from another module.
Records automatically provide accessors for record's fields.</p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a id="v:FireExtinguisher" class="def">FireExtinguisher</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div class="subs fields"><p class="caption">Fields</p><ul><li><dfn class="src"><a id="v:capacity" class="def">capacity</a> :: Integer</dfn><div class="doc empty"> </div></li><li><dfn class="src"><a id="v:feType" class="def">feType</a> :: <a href="Lessons-Lesson02.html#t:FEType" title="Lessons.Lesson02">FEType</a></dfn><div class="doc empty"> </div></li></ul></div></td></tr></table></div><div class="subs instances"><h4 class="instances details-toggle-control details-toggle" data-details-id="i:FireExtinguisher">Instances</h4><details id="i:FireExtinguisher" open="open"><summary class="hide-when-js-enabled">Instances details</summary><table><tr><td class="src clearfix"><span class="inst-left"><span class="instance details-toggle-control details-toggle" data-details-id="i:id:FireExtinguisher:Show:1"></span> Show <a href="Lessons-Lesson03.html#t:FireExtinguisher" title="Lessons.Lesson03">FireExtinguisher</a></span> <a href="src/Lessons.Lesson03.html#line-98" class="link">Source</a> <a href="#t:FireExtinguisher" class="selflink">#</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><details id="i:id:FireExtinguisher:Show:1"><summary class="hide-when-js-enabled">Instance details</summary><p>Defined in <a href="Lessons-Lesson03.html">Lessons.Lesson03</a></p> <div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:showsPrec">showsPrec</a> :: Int -> <a href="Lessons-Lesson03.html#t:FireExtinguisher" title="Lessons.Lesson03">FireExtinguisher</a> -> ShowS</p><p class="src"><a href="#v:show">show</a> :: <a href="Lessons-Lesson03.html#t:FireExtinguisher" title="Lessons.Lesson03">FireExtinguisher</a> -> String</p><p class="src"><a href="#v:showList">showList</a> :: [<a href="Lessons-Lesson03.html#t:FireExtinguisher" title="Lessons.Lesson03">FireExtinguisher</a>] -> ShowS</p></div></details></td></tr></table></details></div></div><div class="top"><p class="src"><a id="v:fe" class="def">fe</a> :: <a href="Lessons-Lesson03.html#t:FireExtinguisher" title="Lessons.Lesson03">FireExtinguisher</a> <a href="src/Lessons.Lesson03.html#fe" class="link">Source</a> <a href="#v:fe" class="selflink">#</a></p><div class="doc"><p>This value represents a specific example of a fire extinguisher.
It has a capacity of 10 and is of type <code><a href="Lessons-Lesson02.html#v:A" title="Lessons.Lesson02">A</a></code>.
Accessor example:</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>capacity fe
</code></strong>10
</pre></div></div><div class="top"><p class="src"><a id="v:fe2" class="def">fe2</a> :: <a href="Lessons-Lesson03.html#t:FireExtinguisher" title="Lessons.Lesson03">FireExtinguisher</a> <a href="src/Lessons.Lesson03.html#fe2" class="link">Source</a> <a href="#v:fe2" class="selflink">#</a></p><div class="doc"><p>This example shows how to use record update syntax in Haskell.
It creates a new extinguisher based on <code><a href="Lessons-Lesson03.html#v:fe" title="Lessons.Lesson03">fe</a></code>, but with the capacity
changed to 100, while keeping all other fields the same.</p></div></div><div class="top"><p class="src"><a id="v:cpcty" class="def">cpcty</a> :: <a href="Lessons-Lesson03.html#t:FireExtinguisher" title="Lessons.Lesson03">FireExtinguisher</a> -> Integer <a href="src/Lessons.Lesson03.html#cpcty" class="link">Source</a> <a href="#v:cpcty" class="selflink">#</a></p><div class="doc"><p>This function extracts the <code><a href="Lessons-Lesson03.html#v:capacity" title="Lessons.Lesson03">capacity</a></code> field from a given
<code><a href="Lessons-Lesson03.html#t:FireExtinguisher" title="Lessons.Lesson03">FireExtinguisher</a></code> record. It demonstrates simple pattern matching
on a record structure (just like usual ADTs)</p></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a id="t:Bucket" class="def">Bucket</a> <a href="src/Lessons.Lesson03.html#Bucket" class="link">Source</a> <a href="#t:Bucket" class="selflink">#</a></p><div class="doc"><p>The <code><a href="Lessons-Lesson03.html#t:Bucket" title="Lessons.Lesson03">Bucket</a></code> data type defines another record-style structure.
It contains a single field, <code><a href="Lessons-Lesson03.html#v:bucketCapacity" title="Lessons.Lesson03">bucketCapacity</a></code>, which stores how
much the bucket can hold. The 'deriving Show' clause again
provides a default string representation.</p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a id="v:Bucket" class="def">Bucket</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><div class="subs fields"><p class="caption">Fields</p><ul><li><dfn class="src"><a id="v:bucketCapacity" class="def">bucketCapacity</a> :: Integer</dfn><div class="doc empty"> </div></li></ul></div></td></tr></table></div><div class="subs instances"><h4 class="instances details-toggle-control details-toggle" data-details-id="i:Bucket">Instances</h4><details id="i:Bucket" open="open"><summary class="hide-when-js-enabled">Instances details</summary><table><tr><td class="src clearfix"><span class="inst-left"><span class="instance details-toggle-control details-toggle" data-details-id="i:id:Bucket:Show:1"></span> Show <a href="Lessons-Lesson03.html#t:Bucket" title="Lessons.Lesson03">Bucket</a></span> <a href="src/Lessons.Lesson03.html#line-127" class="link">Source</a> <a href="#t:Bucket" class="selflink">#</a></td><td class="doc empty"> </td></tr><tr><td colspan="2"><details id="i:id:Bucket:Show:1"><summary class="hide-when-js-enabled">Instance details</summary><p>Defined in <a href="Lessons-Lesson03.html">Lessons.Lesson03</a></p> <div class="subs methods"><p class="caption">Methods</p><p class="src"><a href="#v:showsPrec">showsPrec</a> :: Int -> <a href="Lessons-Lesson03.html#t:Bucket" title="Lessons.Lesson03">Bucket</a> -> ShowS</p><p class="src"><a href="#v:show">show</a> :: <a href="Lessons-Lesson03.html#t:Bucket" title="Lessons.Lesson03">Bucket</a> -> String</p><p class="src"><a href="#v:showList">showList</a> :: [<a href="Lessons-Lesson03.html#t:Bucket" title="Lessons.Lesson03">Bucket</a>] -> ShowS</p></div></details></td></tr></table></details></div></div><div class="top"><p class="src"><a id="v:safeHead" class="def">safeHead</a> :: [a] -> Maybe a <a href="src/Lessons.Lesson03.html#safeHead" class="link">Source</a> <a href="#v:safeHead" class="selflink">#</a></p><div class="doc"><p>What if we do not have a value to return? Other languages have nulls
for that. The <code><a href="Lessons-Lesson03.html#v:safeHead" title="Lessons.Lesson03">safeHead</a></code> function retrieves the first element of a list
in a safe way. Normally, calling <code>head</code> on an empty list causes
a runtime error. To prevent that, this function returns a <code>Maybe</code> value:
'Just a' if the list has a first element, or <code>Nothing</code> if it is empty.</p></div></div><div class="top"><p class="src"><a id="v:safeHeadDefault" class="def">safeHeadDefault</a> :: [a] -> a -> a <a href="src/Lessons.Lesson03.html#safeHeadDefault" class="link">Source</a> <a href="#v:safeHeadDefault" class="selflink">#</a></p><div class="doc"><p>The <code><a href="Lessons-Lesson03.html#v:safeHeadDefault" title="Lessons.Lesson03">safeHeadDefault</a></code> function is a practical extension of <code><a href="Lessons-Lesson03.html#v:safeHead" title="Lessons.Lesson03">safeHead</a></code>.
It takes a list and a default value. If the list is empty, it returns
the default value; otherwise, it returns the first element of the list.
Internally, it uses pattern matching on the result of <code><a href="Lessons-Lesson03.html#v:safeHead" title="Lessons.Lesson03">safeHead</a></code>
to decide which value to return.</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>