-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEta-Prelude-Core.html
74 lines (74 loc) · 15.2 KB
/
Eta-Prelude-Core.html
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!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" /><title>Eta.Prelude.Core</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><script src="haddock-util.js" type="text/javascript"></script><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script><script type="text/javascript">//<![CDATA[
window.onload = function () {pageLoad();setSynopsis("mini_Eta-Prelude-Core.html");};
//]]>
</script></head><body class="no-frame"><div id="package-header"><ul class="links" id="page-menu"><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption empty"> </p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Safe Haskell</th><td>Safe</td></tr></table><p class="caption">Eta.Prelude.Core</p></div><div id="table-of-contents"><p class="caption">Contents</p><ul><li><a href="#g:1">Operators</a><ul><li><a href="#g:2">Flow and application</a></li><li><a href="#g:3">Boolean</a></li></ul></li><li><a href="#g:4">Functions</a><ul><li><a href="#g:5">General functions</a></li><li><a href="#g:6">Boolean</a></li><li><a href="#g:7">IO operations</a></li></ul></li></ul></div><div id="synopsis"><p id="control.syn" class="caption expander" onclick="toggleSection('syn')">Synopsis</p><ul id="section.syn" class="hide" onclick="toggleSection('syn')"><li class="src short"><a href="#v:-124--62-">(|>)</a> :: a -> (a -> b) -> b</li><li class="src short"><a href="#v:-60--124-">(<|)</a> :: (a -> b) -> a -> b</li><li class="src short"><a href="#v:-36-">($)</a> :: (a -> b) -> a -> b</li><li class="src short"><a href="#v:-62--62--62-">(>>>)</a> :: (a -> b) -> (b -> c) -> a -> c</li><li class="src short"><a href="#v:-60--60--60-">(<<<)</a> :: (a -> b) -> (b -> c) -> a -> c</li><li class="src short"><a href="#v:-38--38-">(&&)</a> :: <a href="Eta-Prelude-Types-Bool.html#t:Bool">Bool</a> -> <a href="Eta-Prelude-Types-Bool.html#t:Bool">Bool</a> -> <a href="Eta-Prelude-Types-Bool.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:-124--124-">(||)</a> :: <a href="Eta-Prelude-Types-Bool.html#t:Bool">Bool</a> -> <a href="Eta-Prelude-Types-Bool.html#t:Bool">Bool</a> -> <a href="Eta-Prelude-Types-Bool.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:first">first</a> :: (a, b) -> a</li><li class="src short"><a href="#v:second">second</a> :: (a, b) -> b</li><li class="src short"><a href="#v:identity">identity</a> :: a -> a</li><li class="src short"><a href="#v:flip">flip</a> :: (a -> b -> c) -> b -> a -> c</li><li class="src short"><a href="#v:constantly">constantly</a> :: a -> b -> a</li><li class="src short"><a href="#v:die">die</a> :: [<a href="Eta-Prelude-Types-Char.html#t:Char">Char</a>] -> a</li><li class="src short"><a href="#v:uncurry">uncurry</a> :: (a -> b -> c) -> (a, b) -> c</li><li class="src short"><a href="#v:curry">curry</a> :: ((a, b) -> c) -> a -> b -> c</li><li class="src short"><a href="#v:swap">swap</a> :: (a, b) -> (b, a)</li><li class="src short"><a href="#v:undefined">undefined</a> :: a</li><li class="src short"><a href="#v:stopIfUndefined">stopIfUndefined</a> :: a -> b -> b</li><li class="src short"><a href="#v:not">not</a> :: <a href="Eta-Prelude-Types-Bool.html#t:Bool">Bool</a> -> <a href="Eta-Prelude-Types-Bool.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:print">print</a> :: String -> <a href="Eta-Prelude-Types-IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:printLine">printLine</a> :: String -> <a href="Eta-Prelude-Types-IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:printShow">printShow</a> :: String -> <a href="Eta-Prelude-Types-IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:getArgs">getArgs</a> :: <a href="Eta-Prelude-Types-IO.html#t:IO">IO</a> [String]</li></ul></div><div id="interface"><h1 id="g:1">Operators</h1><h2 id="g:2">Flow and application</h2><div class="top"><p class="src"><a id="v:-124--62-" class="def">(|>)</a> :: a -> (a -> b) -> b <a href="#v:-124--62-" class="selflink">#</a></p><div class="doc"><p>Pipe operator. Functions can be applied using the pipe operator,
reducing parentheses and increasing the code readability.</p><p>Instead of writing</p><pre> (printLine (join ", " (sort names)))
</pre><p>Use the pipe operator:</p><pre> names
|> sort
|> join ", "
|> printLine
</pre></div></div><div class="top"><p class="src"><a id="v:-60--124-" class="def">(<|)</a> :: (a -> b) -> a -> b <a href="#v:-60--124-" class="selflink">#</a></p><div class="doc"><p>Pipe backwards operator.
Applies the function of the left to the value of the right.</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>(+ 2) <| 1
</code></strong>3
</pre></div></div><div class="top"><p class="src"><a id="v:-36-" class="def">($)</a> :: (a -> b) -> a -> b <a href="#v:-36-" class="selflink">#</a></p><div class="doc"><p>Application operator.
Synonymous to (<|), useful for skipping a level of parentheses.</p><p>It can be read as <em>"enclose in parentheses from here to the end of the expression."</em></p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>(print $ show 4)
</code></strong>4
</pre></div></div><div class="top"><p class="src"><a id="v:-62--62--62-" class="def">(>>>)</a> :: (a -> b) -> (b -> c) -> a -> c <a href="#v:-62--62--62-" class="selflink">#</a></p><div class="doc"><p>Forward function composition.</p><p>Creates a new function that acts as a "pipe",
passing the arguments to the first one and then
to the second:</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>addOne x = x + 1
</code></strong><code class="prompt">>>> </code><strong class="userinput"><code>subTwo x = x - 2
</code></strong><code class="prompt">>>> </code><strong class="userinput"><code>subOne = addOne >>> subTwo
</code></strong><code class="prompt">>>> </code><strong class="userinput"><code>subOne 4
</code></strong>3
</pre></div></div><div class="top"><p class="src"><a id="v:-60--60--60-" class="def">(<<<)</a> :: (a -> b) -> (b -> c) -> a -> c <a href="#v:-60--60--60-" class="selflink">#</a></p><div class="doc"><p>Backwards function composition.</p><p>Creates a new function that acts as a "pipe",
passing the arguments to the second one and then
to the first:</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>addOne x = x + 1
</code></strong><code class="prompt">>>> </code><strong class="userinput"><code>subTwo x = x - 2
</code></strong><code class="prompt">>>> </code><strong class="userinput"><code>subOne = subTwo <<< addOne
</code></strong><code class="prompt">>>> </code><strong class="userinput"><code>subOne 4
</code></strong>3
</pre></div></div><h2 id="g:3">Boolean</h2><div class="top"><p class="src"><a id="v:-38--38-" class="def">(&&)</a> :: <a href="Eta-Prelude-Types-Bool.html#t:Bool">Bool</a> -> <a href="Eta-Prelude-Types-Bool.html#t:Bool">Bool</a> -> <a href="Eta-Prelude-Types-Bool.html#t:Bool">Bool</a> <a href="#v:-38--38-" class="selflink">#</a></p><div class="doc"><p>Boolean and</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>True && True
</code></strong>True
<code class="prompt">>>> </code><strong class="userinput"><code>True && False
</code></strong>False
</pre></div></div><div class="top"><p class="src"><a id="v:-124--124-" class="def">(||)</a> :: <a href="Eta-Prelude-Types-Bool.html#t:Bool">Bool</a> -> <a href="Eta-Prelude-Types-Bool.html#t:Bool">Bool</a> -> <a href="Eta-Prelude-Types-Bool.html#t:Bool">Bool</a> <a href="#v:-124--124-" class="selflink">#</a></p><div class="doc"><p>Boolean or</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>True || True
</code></strong>True
<code class="prompt">>>> </code><strong class="userinput"><code>True || False
</code></strong>True
</pre></div></div><h1 id="g:4">Functions</h1><h2 id="g:5">General functions</h2><div class="top"><p class="src"><a id="v:first" class="def">first</a> :: (a, b) -> a <a href="#v:first" class="selflink">#</a></p><div class="doc"><p>Extract the first component of a pair</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>first (1, 2)
</code></strong>1
</pre></div></div><div class="top"><p class="src"><a id="v:second" class="def">second</a> :: (a, b) -> b <a href="#v:second" class="selflink">#</a></p><div class="doc"><p>Extract the second component of a pair</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>second (1, 2)
</code></strong>2
</pre></div></div><div class="top"><p class="src"><a id="v:identity" class="def">identity</a> :: a -> a <a href="#v:identity" class="selflink">#</a></p><div class="doc"><p>The identity function,
returns the passed argument as it is</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>identity 1
</code></strong>1
</pre></div></div><div class="top"><p class="src"><a id="v:flip" class="def">flip</a> :: (a -> b -> c) -> b -> a -> c <a href="#v:flip" class="selflink">#</a></p><div class="doc"><p>Flips the arguments of a function</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>subtract a b = a - b
</code></strong><code class="prompt">>>> </code><strong class="userinput"><code>inverseSubtract = flip subtract
</code></strong><code class="prompt">>>> </code><strong class="userinput"><code>subtract 3 2
</code></strong>1
<code class="prompt">>>> </code><strong class="userinput"><code>inverseSubtract 3 2
</code></strong>-1
</pre></div></div><div class="top"><p class="src"><a id="v:constantly" class="def">constantly</a> :: a -> b -> a <a href="#v:constantly" class="selflink">#</a></p><div class="doc"><p>Constructs a function that returns the same output for
the same input</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>universe = constantly 42
</code></strong><code class="prompt">>>> </code><strong class="userinput"><code>universe 35
</code></strong>42
<code class="prompt">>>> </code><strong class="userinput"><code>map (constantly 10) [1..3]
</code></strong>[10,10,10]
</pre></div></div><div class="top"><p class="src"><a id="v:die" class="def">die</a> :: [<a href="Eta-Prelude-Types-Char.html#t:Char">Char</a>] -> a <a href="#v:die" class="selflink">#</a></p><div class="doc"><div class="warning"><p>Warning: die detected: Partial functions should be avoided</p></div><p>Stops execution and displays an error message.</p></div></div><div class="top"><p class="src"><a id="v:uncurry" class="def">uncurry</a> :: (a -> b -> c) -> (a, b) -> c <a href="#v:uncurry" class="selflink">#</a></p><div class="doc"><p>Converts a two argument function in a
function that accepts a pair</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>addElements = uncurry (+)
</code></strong><code class="prompt">>>> </code><strong class="userinput"><code>addElements (1,2)
</code></strong>3
</pre></div></div><div class="top"><p class="src"><a id="v:curry" class="def">curry</a> :: ((a, b) -> c) -> a -> b -> c <a href="#v:curry" class="selflink">#</a></p><div class="doc"><p>Converts a function that accepts a pair in a
two argument function</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>firstArgument = curry first
</code></strong><code class="prompt">>>> </code><strong class="userinput"><code>firstArgument 1 2
</code></strong>1
</pre></div></div><div class="top"><p class="src"><a id="v:swap" class="def">swap</a> :: (a, b) -> (b, a) <a href="#v:swap" class="selflink">#</a></p><div class="doc"><p>Swaps the components of a pair</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>swap (1,2)
</code></strong>(2,1)
</pre></div></div><div class="top"><p class="src"><a id="v:undefined" class="def">undefined</a> :: a <a href="#v:undefined" class="selflink">#</a></p><div class="doc"><p>A value that can be of any type. The compiler will recognize this
and insert an error message appropriate to the context where it
appears.</p><p><em>Usually, also called <strong>Bottom</strong></em></p></div></div><div class="top"><p class="src"><a id="v:stopIfUndefined" class="def">stopIfUndefined</a> :: a -> b -> b <a href="#v:stopIfUndefined" class="selflink">#</a></p><div class="doc"><p>Returns <code><a href="Eta-Prelude-Core.html#v:undefined">undefined</a></code> if <code>a</code> is <code><a href="Eta-Prelude-Core.html#v:undefined">undefined</a></code>, otherwise returns <code>b</code></p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>stopIfUndefined 1 2
</code></strong>2
</pre></div></div><h2 id="g:6">Boolean</h2><div class="top"><p class="src"><a id="v:not" class="def">not</a> :: <a href="Eta-Prelude-Types-Bool.html#t:Bool">Bool</a> -> <a href="Eta-Prelude-Types-Bool.html#t:Bool">Bool</a> <a href="#v:not" class="selflink">#</a></p><div class="doc"><p>Boolean not</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>not True
</code></strong>False
</pre></div></div><h2 id="g:7">IO operations</h2><div class="top"><p class="src"><a id="v:print" class="def">print</a> :: String -> <a href="Eta-Prelude-Types-IO.html#t:IO">IO</a> () <a href="#v:print" class="selflink">#</a></p><div class="doc"><p>Print a <code>String</code> on screen</p></div></div><div class="top"><p class="src"><a id="v:printLine" class="def">printLine</a> :: String -> <a href="Eta-Prelude-Types-IO.html#t:IO">IO</a> () <a href="#v:printLine" class="selflink">#</a></p><div class="doc"><p>Print a <code>String</code> on screen, followed by a newline.</p></div></div><div class="top"><p class="src"><a id="v:printShow" class="def">printShow</a> :: String -> <a href="Eta-Prelude-Types-IO.html#t:IO">IO</a> () <a href="#v:printShow" class="selflink">#</a></p><div class="doc"><p>Converts the value to a <code>String</code> using <code><a href="Eta-Prelude-Classes-Show.html#v:show">show</a></code> and
then <code><a href="Eta-Prelude-Core.html#v:printLine">printLine</a></code>s it.</p></div></div><div class="top"><p class="src"><a id="v:getArgs" class="def">getArgs</a> :: <a href="Eta-Prelude-Types-IO.html#t:IO">IO</a> [String] <a href="#v:getArgs" class="selflink">#</a></p><div class="doc"><p>Returns the arguments of the program</p></div></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.17.4</p></div></body></html>