「Program=Proof筆記」修訂間的差異

增加 650 位元組 、 2024年3月3日 (星期日)
行 177: 行 177:
<pre>let f = function ... 即 let f x = match x with ...</pre>
<pre>let f = function ... 即 let f x = match x with ...</pre>


====Bool====
<pre>type bool = True | False</pre>
====List====
<pre>type 'a list =
| Nil
| Cons of 'a * 'a list</pre>
====coproducts====
<pre>type ('a, 'b) either =
| Left of 'a
| Right of 'b</pre>
====unit====
<pre>type unit = | T</pre>
只有這個值 <code>()</code>
====Empty====
<pre>type Empty = |</pre>
====Natural Number====
<pre>type Nat =
|Zero
|Suc of nat</pre>
====例外處理:Option type and exception====
處理例外的方式
Option type
<pre>type 'a option =
| Some of 'a
| None
</pre>
exception
<pre>let hd l =
  match l with
| x::l -> x
| [] -> raise Not_found</pre>
搭配
<pre>try
...
with
| Not_found -> ...</pre>


[[分類:資訊]]
[[分類:資訊]]
[[分類:邏輯學]]
[[分類:邏輯學]]