group__group-Applicative.html 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <!--
  2. Copyright Louis Dionne 2013-2017
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  5. -->
  6. <!-- boost-no-inspect -->
  7. <!-- HTML header for doxygen 1.8.9.1-->
  8. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  9. <html xmlns="http://www.w3.org/1999/xhtml">
  10. <head>
  11. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  12. <meta http-equiv="X-UA-Compatible" content="IE=9"/>
  13. <meta name="generator" content="Doxygen 1.8.15"/>
  14. <title>Boost.Hana: Applicative</title>
  15. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  16. <script type="text/javascript" src="jquery.js"></script>
  17. <script type="text/javascript" src="dynsections.js"></script>
  18. <link href="navtree.css" rel="stylesheet" type="text/css"/>
  19. <script type="text/javascript" src="resize.js"></script>
  20. <script type="text/javascript" src="navtreedata.js"></script>
  21. <script type="text/javascript" src="navtree.js"></script>
  22. <script type="text/javascript">
  23. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  24. $(document).ready(initResizable);
  25. /* @license-end */</script>
  26. <link href="search/search.css" rel="stylesheet" type="text/css"/>
  27. <script type="text/javascript" src="search/searchdata.js"></script>
  28. <script type="text/javascript" src="search/search.js"></script>
  29. <script type="text/javascript">
  30. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  31. $(document).ready(function() { init_search(); });
  32. /* @license-end */
  33. </script>
  34. <script type="text/x-mathjax-config">
  35. MathJax.Hub.Config({
  36. extensions: ["tex2jax.js"],
  37. jax: ["input/TeX","output/HTML-CSS"],
  38. });
  39. // Copyright Louis Dionne 2013-2017
  40. // Distributed under the Boost Software License, Version 1.0.
  41. // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  42. MathJax.Hub.Config({
  43. "HTML-CSS": {
  44. linebreaks: {
  45. automatic: true,
  46. width: "75% container"
  47. }
  48. }
  49. });
  50. </script><script type="text/javascript" async="async" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js"></script>
  51. <link href="doxygen.css" rel="stylesheet" type="text/css" />
  52. <!-- Additional javascript for drawing charts. -->
  53. <script type="text/javascript" src="highcharts.js"></script>
  54. <script type="text/javascript" src="highcharts-data.js"></script>
  55. <script type="text/javascript" src="highcharts-exporting.js"></script>
  56. <script type="text/javascript" src="chart.js"></script>
  57. <script type="text/javascript" src="hana.js"></script>
  58. </head>
  59. <body>
  60. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  61. <div id="titlearea">
  62. <table cellspacing="0" cellpadding="0">
  63. <tbody>
  64. <tr style="height: 56px;">
  65. <td id="projectlogo"><img alt="Logo" src="Boost.png"/></td>
  66. <td style="padding-left: 0.5em;">
  67. <div id="projectname">Boost.Hana
  68. &#160;<span id="projectnumber">1.6.0</span>
  69. </div>
  70. <div id="projectbrief">Your standard library for metaprogramming</div>
  71. </td>
  72. <td> <div id="MSearchBox" class="MSearchBoxInactive">
  73. <span class="left">
  74. <img id="MSearchSelect" src="search/mag_sel.png"
  75. onmouseover="return searchBox.OnSearchSelectShow()"
  76. onmouseout="return searchBox.OnSearchSelectHide()"
  77. alt=""/>
  78. <input type="text" id="MSearchField" value="Search" accesskey="S"
  79. onfocus="searchBox.OnSearchFieldFocus(true)"
  80. onblur="searchBox.OnSearchFieldFocus(false)"
  81. onkeyup="searchBox.OnSearchFieldChange(event)"/>
  82. </span><span class="right">
  83. <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
  84. </span>
  85. </div>
  86. </td>
  87. </tr>
  88. </tbody>
  89. </table>
  90. </div>
  91. <!-- end header part -->
  92. <!-- Generated by Doxygen 1.8.15 -->
  93. <script type="text/javascript">
  94. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  95. var searchBox = new SearchBox("searchBox", "search",false,'Search');
  96. /* @license-end */
  97. </script>
  98. </div><!-- top -->
  99. <div id="side-nav" class="ui-resizable side-nav-resizable">
  100. <div id="nav-tree">
  101. <div id="nav-tree-contents">
  102. <div id="nav-sync" class="sync"></div>
  103. </div>
  104. </div>
  105. <div id="splitbar" style="-moz-user-select:none;"
  106. class="ui-resizable-handle">
  107. </div>
  108. </div>
  109. <script type="text/javascript">
  110. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  111. $(document).ready(function(){initNavTree('group__group-Applicative.html','');});
  112. /* @license-end */
  113. </script>
  114. <div id="doc-content">
  115. <!-- window showing the filter options -->
  116. <div id="MSearchSelectWindow"
  117. onmouseover="return searchBox.OnSearchSelectShow()"
  118. onmouseout="return searchBox.OnSearchSelectHide()"
  119. onkeydown="return searchBox.OnSearchSelectKey(event)">
  120. </div>
  121. <!-- iframe showing the search results (closed by default) -->
  122. <div id="MSearchResultsWindow">
  123. <iframe src="javascript:void(0)" frameborder="0"
  124. name="MSearchResults" id="MSearchResults">
  125. </iframe>
  126. </div>
  127. <div class="header">
  128. <div class="summary">
  129. <a href="#var-members">Variables</a> </div>
  130. <div class="headertitle">
  131. <div class="title">Applicative<div class="ingroups"><a class="el" href="group__group-concepts.html">Concepts</a></div></div> </div>
  132. </div><!--header-->
  133. <div class="contents">
  134. <a name="details" id="details"></a><h2 class="groupheader">Description</h2>
  135. <p>The <code>Applicative</code> concept represents <code>Functor</code>s with the ability to lift values and combine computations. </p>
  136. <p>A <code>Functor</code> can only take a normal function and map it over a structure containing values to obtain a new structure containing values. Intuitively, an <code>Applicative</code> can also take a value and lift it into the structure. In addition, an <code>Applicative</code> can take a structure containing functions and apply it to a structure containing values to obtain a new structure containing values. By currying the function(s) inside the structure, it is then also possible to apply n-ary functions to n structures containing values.</p>
  137. <dl class="section note"><dt>Note</dt><dd>This documentation does not go into much details about the nature of applicatives. However, the <a href="https://wiki.haskell.org/Typeclassopedia#Applicative">Typeclassopedia</a> is a nice Haskell-oriented resource where such information can be found.</dd></dl>
  138. <h2>Minimal complete definition </h2>
  139. <p><code>lift</code> and <code>ap</code> satisfying the laws below. An <code>Applicative</code> must also be a <code>Functor</code>.</p>
  140. <h2>Laws </h2>
  141. <p>Given an <code>Applicative</code> <code>F</code>, the following laws must be satisfied:</p><ol type="1">
  142. <li>Identity<br />
  143. For all objects <code>xs</code> of tag <code>F(A)</code>, <div class="fragment"><div class="line"><a class="code" href="group__group-Applicative.html#ga6176a32953dbbdee96e3ab3c73e4c890">ap</a>(lift&lt;F&gt;(<span class="keywordtype">id</span>), xs) == xs</div></div><!-- fragment --></li>
  144. <li>Composition<br />
  145. For all objects <code>xs</code> of tag <code>F(A)</code> and functions-in-an-applicative \( fs : F(B \to C) \), \( gs : F(A \to B) \), <div class="fragment"><div class="line"><a class="code" href="group__group-Applicative.html#ga6176a32953dbbdee96e3ab3c73e4c890">ap</a>(<a class="code" href="group__group-Applicative.html#ga6176a32953dbbdee96e3ab3c73e4c890">ap</a>(lift&lt;F&gt;(<a class="code" href="group__group-functional.html#ga3b16146e53efcdf9ecbb9a7b21f8cd0b">compose</a>), fs, gs), xs) == <a class="code" href="group__group-Applicative.html#ga6176a32953dbbdee96e3ab3c73e4c890">ap</a>(fs, <a class="code" href="group__group-Applicative.html#ga6176a32953dbbdee96e3ab3c73e4c890">ap</a>(gs, xs))</div></div><!-- fragment --></li>
  146. <li>Homomorphism<br />
  147. For all objects <code>x</code> of tag <code>A</code> and functions \( f : A \to B \), <div class="fragment"><div class="line"><a class="code" href="group__group-Applicative.html#ga6176a32953dbbdee96e3ab3c73e4c890">ap</a>(lift&lt;F&gt;(f), lift&lt;F&gt;(x)) == lift&lt;F&gt;(f(x))</div></div><!-- fragment --></li>
  148. <li>Interchange<br />
  149. For all objects <code>x</code> of tag <code>A</code> and functions-in-an-applicative \( fs : F(A \to B) \), <div class="fragment"><div class="line"><a class="code" href="group__group-Applicative.html#ga6176a32953dbbdee96e3ab3c73e4c890">ap</a>(fs, lift&lt;F&gt;(x)) == <a class="code" href="group__group-Applicative.html#ga6176a32953dbbdee96e3ab3c73e4c890">ap</a>(lift&lt;F&gt;(<a class="code" href="group__group-functional.html#ga30027c383676084be151ef3c6cf2829f">apply</a>(-, x)), fs)</div></div><!-- fragment --> where <code>apply(-, x)</code> denotes the partial application of the <code>apply</code> function from the <a class="el" href="group__group-functional.html">Functional</a> module to the <code>x</code> argument.</li>
  150. </ol>
  151. <p>As a consequence of these laws, the model of <code>Functor</code> for <code>F</code> will satisfy the following for all objects <code>xs</code> of tag <code>F(A)</code> and functions \( f : A \to B \): </p><div class="fragment"><div class="line"><a class="code" href="group__group-Functor.html#ga5a8975f6e55375d5b6038a9c36ee63e7">transform</a>(xs, f) == <a class="code" href="group__group-Applicative.html#ga6176a32953dbbdee96e3ab3c73e4c890">ap</a>(lift&lt;F&gt;(f), xs)</div></div><!-- fragment --><h2>Refined concept </h2>
  152. <ol type="1">
  153. <li><code>Functor</code> (free model)<br />
  154. As a consequence of the laws, any <code>Applicative F</code> can be made a <code>Functor</code> by setting <div class="fragment"><div class="line"><a class="code" href="group__group-Functor.html#ga5a8975f6e55375d5b6038a9c36ee63e7">transform</a>(xs, f) = <a class="code" href="group__group-Applicative.html#ga6176a32953dbbdee96e3ab3c73e4c890">ap</a>(lift&lt;F&gt;(f), xs)</div></div><!-- fragment --></li>
  155. </ol>
  156. <h2>Concrete models </h2>
  157. <p><code><a class="el" href="structboost_1_1hana_1_1lazy.html" title="hana::lazy implements superficial laziness via a monadic interface.">hana::lazy</a></code>, <code><a class="el" href="structboost_1_1hana_1_1optional.html" title="Optional value whose optional-ness is known at compile-time.">hana::optional</a></code>, <code><a class="el" href="structboost_1_1hana_1_1tuple.html" title="General purpose index-based heterogeneous sequence with a fixed length.">hana::tuple</a></code></p>
  158. <p><a class="anchor" id="applicative-transformation"></a></p><h2>Structure-preserving functions </h2>
  159. <p>An <em>applicative transformation</em> is a function \( t : F(X) \to G(X) \) between two Applicatives <code>F</code> and <code>G</code>, where <code>X</code> can be any tag, and which preserves the operations of an Applicative. In other words, for all objects <code>x</code> of tag <code>X</code>, functions-in-an-applicative \( fs : F(X \to Y) \) and objects <code>xs</code> of tag <code>F(X)</code>, </p><div class="fragment"><div class="line">t(lift&lt;F&gt;(x)) == lift&lt;G&gt;(x)</div><div class="line">t(<a class="code" href="group__group-Applicative.html#ga6176a32953dbbdee96e3ab3c73e4c890">ap</a>(fs, xs)) == <a class="code" href="group__group-Applicative.html#ga6176a32953dbbdee96e3ab3c73e4c890">ap</a>(t(fs), t(xs))</div></div><!-- fragment --> <table class="memberdecls">
  160. <tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="var-members"></a>
  161. Variables</h2></td></tr>
  162. <tr class="memitem:ga6176a32953dbbdee96e3ab3c73e4c890"><td class="memItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-Applicative.html#ga6176a32953dbbdee96e3ab3c73e4c890">boost::hana::ap</a></td></tr>
  163. <tr class="memdesc:ga6176a32953dbbdee96e3ab3c73e4c890"><td class="mdescLeft">&#160;</td><td class="mdescRight">Lifted application.Specifically, <code>ap</code> applies a structure containing functions to a structure containing values, and returns a new structure containing values. The exact way in which the functions are applied to the values depends on the <code>Applicative</code>. <a href="group__group-Applicative.html#ga6176a32953dbbdee96e3ab3c73e4c890">More...</a><br /></td></tr>
  164. <tr class="separator:ga6176a32953dbbdee96e3ab3c73e4c890"><td class="memSeparator" colspan="2">&#160;</td></tr>
  165. <tr class="memitem:ga712038d7abbc7159f8792788f7cd0c73"><td class="memTemplParams" colspan="2">template&lt;typename A &gt; </td></tr>
  166. <tr class="memitem:ga712038d7abbc7159f8792788f7cd0c73"><td class="memTemplItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="group__group-Applicative.html#ga712038d7abbc7159f8792788f7cd0c73">boost::hana::lift</a></td></tr>
  167. <tr class="memdesc:ga712038d7abbc7159f8792788f7cd0c73"><td class="mdescLeft">&#160;</td><td class="mdescRight">Lift a value into an <code>Applicative</code> structure.<code>lift&lt;A&gt;</code> takes a normal value and embeds it into a structure whose shape is represented by the <code>A</code> <code>Applicative</code>. Note that the value may be a function, in which case the created structure may be <code>ap</code>plied to another <code>Applicative</code> structure containing values. <a href="group__group-Applicative.html#ga712038d7abbc7159f8792788f7cd0c73">More...</a><br /></td></tr>
  168. <tr class="separator:ga712038d7abbc7159f8792788f7cd0c73"><td class="memSeparator" colspan="2">&#160;</td></tr>
  169. </table>
  170. <h2 class="groupheader">Variable Documentation</h2>
  171. <a id="ga6176a32953dbbdee96e3ab3c73e4c890"></a>
  172. <h2 class="memtitle"><span class="permalink"><a href="#ga6176a32953dbbdee96e3ab3c73e4c890">&#9670;&nbsp;</a></span>ap</h2>
  173. <div class="memitem">
  174. <div class="memproto">
  175. <table class="memname">
  176. <tr>
  177. <td class="memname">constexpr auto boost::hana::ap</td>
  178. </tr>
  179. </table>
  180. </div><div class="memdoc">
  181. <p><code>#include &lt;<a class="el" href="fwd_2ap_8hpp.html">boost/hana/fwd/ap.hpp</a>&gt;</code></p>
  182. <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&amp;&amp; f, <span class="keyword">auto</span>&amp;&amp; ...x) -&gt; decltype(<span class="keyword">auto</span>) {</div><div class="line"> <span class="keywordflow">return</span> tag-dispatched;</div><div class="line"> }</div></div><!-- fragment -->
  183. <p>Lifted application.Specifically, <code>ap</code> applies a structure containing functions to a structure containing values, and returns a new structure containing values. The exact way in which the functions are applied to the values depends on the <code>Applicative</code>. </p>
  184. <p><code>ap</code> can be called with two arguments or more; the functions in the <code>f</code> structure are curried and then applied to the values in each <code>x...</code> structure using the binary form of <code>ap</code>. Note that this requires the number of <code>x...</code> must match the arity of the functions in the <code>f</code> structure. In other words, <code>ap(f, x1, ..., xN)</code> is equivalent to </p><div class="fragment"><div class="line">((<a class="code" href="group__group-functional.html#ga49ea872ade5ac8f6c10052c495302e89">curry</a>(f) <a class="code" href="group__group-Applicative.html#ga6176a32953dbbdee96e3ab3c73e4c890">ap</a> x1) <a class="code" href="group__group-Applicative.html#ga6176a32953dbbdee96e3ab3c73e4c890">ap</a> x2) ... <a class="code" href="group__group-Applicative.html#ga6176a32953dbbdee96e3ab3c73e4c890">ap</a> xN</div></div><!-- fragment --><p> where <code>x ap y</code> is just <code>ap(x, y)</code> written in infix notation to emphasize the left associativity.</p>
  185. <h2>Signature </h2>
  186. <p>Given an Applicative <code>A</code>, the signature is \( \mathtt{ap} : A(T_1 \times \cdots \times T_n \to U) \times A(T_1) \times \cdots \times A(T_n) \to A(U) \).</p>
  187. <dl class="params"><dt>Parameters</dt><dd>
  188. <table class="params">
  189. <tr><td class="paramname">f</td><td>A structure containing function(s).</td></tr>
  190. <tr><td class="paramname">x...</td><td>Structure(s) containing value(s) and on which <code>f</code> is applied. The number of structures must match the arity of the functions in the <code>f</code> structure.</td></tr>
  191. </table>
  192. </dd>
  193. </dl>
  194. <h2>Example </h2>
  195. <div class="fragment"><div class="line"><span class="comment">// Copyright Louis Dionne 2013-2017</span></div><div class="line"><span class="comment">// Distributed under the Boost Software License, Version 1.0.</span></div><div class="line"><span class="comment">// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="ap_8hpp.html">boost/hana/ap.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="config_8hpp.html">boost/hana/config.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="equal_8hpp.html">boost/hana/equal.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="optional_8hpp.html">boost/hana/optional.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="tuple_8hpp.html">boost/hana/tuple.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;functional&gt;</span></div><div class="line"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() {</div><div class="line"> <span class="comment">// with tuples</span></div><div class="line"> static_assert(</div><div class="line"> <a class="code" href="group__group-Applicative.html#ga6176a32953dbbdee96e3ab3c73e4c890">hana::ap</a>(hana::make_tuple(std::plus&lt;&gt;{}), hana::make_tuple(1, 2),</div><div class="line"> hana::make_tuple(3, 4, 5))</div><div class="line"> ==</div><div class="line"> hana::make_tuple(</div><div class="line"> 1 + 3, 1 + 4, 1 + 5,</div><div class="line"> 2 + 3, 2 + 4, 2 + 5</div><div class="line"> )</div><div class="line"> , <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"></div><div class="line"> <span class="comment">// with optional values</span></div><div class="line"> BOOST_HANA_CONSTEXPR_LAMBDA <span class="keyword">auto</span> multiply = [](<span class="keyword">auto</span> a, <span class="keyword">auto</span> b, <span class="keyword">auto</span> c) {</div><div class="line"> <span class="keywordflow">return</span> a * b * c;</div><div class="line"> };</div><div class="line"></div><div class="line"> <a class="code" href="group__group-assertions.html#gac7aafc41e4dcc7d1f1929fb00f010d2a">BOOST_HANA_CONSTEXPR_CHECK</a>(</div><div class="line"> <a class="code" href="group__group-Applicative.html#ga6176a32953dbbdee96e3ab3c73e4c890">hana::ap</a>(hana::just(multiply), hana::just(1),</div><div class="line"> hana::just(2),</div><div class="line"> hana::just(3))</div><div class="line"> ==</div><div class="line"> hana::just(1 * 2 * 3)</div><div class="line"> );</div><div class="line"></div><div class="line"> <a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(</div><div class="line"> <a class="code" href="group__group-Applicative.html#ga6176a32953dbbdee96e3ab3c73e4c890">hana::ap</a>(hana::just(multiply), hana::just(1),</div><div class="line"> hana::nothing,</div><div class="line"> hana::just(3))</div><div class="line"> ==</div><div class="line"> hana::nothing</div><div class="line"> );</div><div class="line">}</div></div><!-- fragment --><dl class="todo"><dt><b><a class="el" href="todo.html#_todo000004">Todo:</a></b></dt><dd>Consider giving access to all the arguments to the tag-dispatched implementation for performance purposes. </dd></dl>
  196. </div>
  197. </div>
  198. <a id="ga712038d7abbc7159f8792788f7cd0c73"></a>
  199. <h2 class="memtitle"><span class="permalink"><a href="#ga712038d7abbc7159f8792788f7cd0c73">&#9670;&nbsp;</a></span>lift</h2>
  200. <div class="memitem">
  201. <div class="memproto">
  202. <div class="memtemplate">
  203. template&lt;typename A &gt; </div>
  204. <table class="memname">
  205. <tr>
  206. <td class="memname">constexpr auto boost::hana::lift</td>
  207. </tr>
  208. </table>
  209. </div><div class="memdoc">
  210. <p><code>#include &lt;<a class="el" href="fwd_2lift_8hpp.html">boost/hana/fwd/lift.hpp</a>&gt;</code></p>
  211. <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&amp;&amp; x) {</div><div class="line"> <span class="keywordflow">return</span> tag-dispatched;</div><div class="line"> }</div></div><!-- fragment -->
  212. <p>Lift a value into an <code>Applicative</code> structure.<code>lift&lt;A&gt;</code> takes a normal value and embeds it into a structure whose shape is represented by the <code>A</code> <code>Applicative</code>. Note that the value may be a function, in which case the created structure may be <code>ap</code>plied to another <code>Applicative</code> structure containing values. </p>
  213. <h2>Signature </h2>
  214. <p>Given an Applicative <code>A</code>, the signature is \( \mathtt{lift}_A : T \to A(T) \).</p>
  215. <dl class="tparams"><dt>Template Parameters</dt><dd>
  216. <table class="tparams">
  217. <tr><td class="paramname">A</td><td>A tag representing the <code>Applicative</code> into which the value is lifted.</td></tr>
  218. </table>
  219. </dd>
  220. </dl>
  221. <dl class="params"><dt>Parameters</dt><dd>
  222. <table class="params">
  223. <tr><td class="paramname">x</td><td>The value to lift into the applicative.</td></tr>
  224. </table>
  225. </dd>
  226. </dl>
  227. <h2>Example </h2>
  228. <div class="fragment"><div class="line"><span class="comment">// Copyright Louis Dionne 2013-2017</span></div><div class="line"><span class="comment">// Distributed under the Boost Software License, Version 1.0.</span></div><div class="line"><span class="comment">// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="equal_8hpp.html">boost/hana/equal.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="lift_8hpp.html">boost/hana/lift.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="optional_8hpp.html">boost/hana/optional.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="tuple_8hpp.html">boost/hana/tuple.hpp</a>&gt;</span></div><div class="line"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div><div class="line"></div><div class="line"></div><div class="line">static_assert(hana::lift&lt;hana::tuple_tag&gt;(<span class="charliteral">&#39;x&#39;</span>) == hana::make_tuple(<span class="charliteral">&#39;x&#39;</span>), <span class="stringliteral">&quot;&quot;</span>);</div><div class="line">static_assert(hana::lift&lt;hana::optional_tag&gt;(<span class="charliteral">&#39;x&#39;</span>) == hana::just(<span class="charliteral">&#39;x&#39;</span>), <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment -->
  229. </div>
  230. </div>
  231. </div><!-- contents -->
  232. </div><!-- doc-content -->
  233. <!--
  234. Copyright Louis Dionne 2013-2017
  235. Distributed under the Boost Software License, Version 1.0.
  236. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  237. -->
  238. <!-- boost-no-inspect -->
  239. <!-- HTML footer for doxygen 1.8.9.1-->
  240. <!-- start footer part -->
  241. <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  242. <ul>
  243. </ul>
  244. </div>
  245. </body>
  246. </html>