archivesOfToyLang/tshunhue/docs/build/html/型別.html

296 lines
No EOL
9.3 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html class="writer-html5" lang="zh-tw" >
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>型別 &mdash; Tshunhue Documents documentation</title>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<!--[if lt IE 9]>
<script src="_static/js/html5shiv.min.js"></script>
<![endif]-->
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script>
<script src="_static/underscore.js"></script>
<script src="_static/doctools.js"></script>
<script src="_static/language_data.js"></script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="prev" title="基本函數介紹" href="%E5%9F%BA%E6%9C%AC%E5%87%BD%E6%95%B8%E4%BB%8B%E7%B4%B9.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="index.html" class="icon icon-home" alt="Documentation Home"> Tshunhue Documents
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<p class="caption"><span class="caption-text">Contents</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="%E5%9F%BA%E6%9C%AC%E5%87%BD%E6%95%B8%E4%BB%8B%E7%B4%B9.html">基本函數介紹</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">型別</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#id2">簡單型別</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#id3">數字</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id4">字串</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id5">布林</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#id6">複雜型別</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#id7">自訂型別</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">Tshunhue Documents</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html" class="icon icon-home"></a> &raquo;</li>
<li>型別</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/型別.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="id1">
<h1>型別<a class="headerlink" href="#id1" title="Permalink to this headline"></a></h1>
<div class="section" id="id2">
<h2>簡單型別<a class="headerlink" href="#id2" title="Permalink to this headline"></a></h2>
<div class="section" id="id3">
<h3>數字<a class="headerlink" href="#id3" title="Permalink to this headline"></a></h3>
<ul class="simple">
<li><p><cite>int</cite>:整數,初期可用 64 位元帶符號整數處理。</p></li>
<li><p><cite>dou</cite>:雙精度浮點數</p></li>
</ul>
</div>
<div class="section" id="id4">
<h3>字串<a class="headerlink" href="#id4" title="Permalink to this headline"></a></h3>
<ul class="simple">
<li><p><cite>str</cite>:字串</p></li>
</ul>
<p>暫不支援 <cite>char</cite></p>
</div>
<div class="section" id="id5">
<h3>布林<a class="headerlink" href="#id5" title="Permalink to this headline"></a></h3>
<ul class="simple">
<li><p><cite>bool</cite>:布林值。#t真值#f假值。</p></li>
</ul>
</div>
</div>
<div class="section" id="id6">
<h2>複雜型別<a class="headerlink" href="#id6" title="Permalink to this headline"></a></h2>
<div class="section" id="id7">
<h3>自訂型別<a class="headerlink" href="#id7" title="Permalink to this headline"></a></h3>
<p>可以自訂 product type 或 sum type。為求簡化不支援型別當參數。</p>
<dl class="py function">
<dt>
<code class="sig-name descname">(Type TYPE-NAME (Type-constronctor x1 x2 ...))</code></dt>
<dd></dd></dl>
<dl class="py function">
<dt>
<code class="sig-name descname">(Type TYPE-NAME (U (Type-const1 x1 x2 ...)(Type-const2 x1 x2 ...)...))</code></dt>
<dd></dd></dl>
<dl class="py function">
<dt>
<code class="sig-name descname">(Type TYPE-NAME (Type-constronctor))</code></dt>
<dd></dd></dl>
<dl class="py function">
<dt>
<code class="sig-name descname">(Type TYPE-NAME (U (Type-const1)(Type-const2)...))</code></dt>
<dd></dd></dl>
<p>U 是 union 的意思,指 Sum Type。</p>
<p>例如:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">(</span><span class="n">Type</span> <span class="n">IntPair</span> <span class="p">(</span><span class="n">IntPair</span> <span class="n">Int</span> <span class="n">Int</span><span class="p">))</span>
</pre></div>
</div>
<p>如果可以模式匹配,就變這樣:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">(</span>\ <span class="p">((</span><span class="n">IntPair</span> <span class="n">x</span><span class="p">))</span>
<span class="p">(</span><span class="n">match</span> <span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="p">((</span><span class="n">IntPair</span> <span class="mi">7</span> <span class="mi">9</span><span class="p">)</span> <span class="mi">9</span><span class="p">)</span>
<span class="p">((</span><span class="n">IntPair</span> <span class="mi">8</span> <span class="n">a</span><span class="p">)</span> <span class="n">a</span><span class="p">)</span>
<span class="p">((</span><span class="n">IntPair</span> <span class="n">x</span> <span class="n">y</span><span class="p">)</span> <span class="p">(</span><span class="o">+</span> <span class="n">x</span> <span class="n">y</span><span class="p">))))</span>
</pre></div>
</div>
<p>Sum Type 的用法:</p>
<p>(Type OrigColor (U (Red)(Green)(Blue))) ; 三原色</p>
<p>如果可以模式匹配,就變這樣:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">(</span><span class="n">orig</span><span class="o">-</span><span class="n">color</span><span class="o">-</span><span class="n">to</span><span class="o">-</span><span class="nb">str</span> <span class="p">((</span><span class="n">OrigColor</span> <span class="n">x</span><span class="p">))</span>
<span class="p">(</span><span class="n">match</span> <span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="p">((</span><span class="n">Red</span><span class="p">)</span> <span class="s2">&quot;Red&quot;</span><span class="p">)</span>
<span class="p">((</span><span class="n">Green</span><span class="p">)</span> <span class="s2">&quot;Green&quot;</span><span class="p">)</span>
<span class="p">((</span><span class="n">Blue</span><span class="p">)</span> <span class="s2">&quot;Blue&quot;</span><span class="p">)))</span>
</pre></div>
</div>
</div>
</div>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="%E5%9F%BA%E6%9C%AC%E5%87%BD%E6%95%B8%E4%BB%8B%E7%B4%B9.html" class="btn btn-neutral float-left" title="基本函數介紹" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2020, Yoxem Chen
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a
<a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>