以下のような普通の関数を考える。
let add x y = x + y;;
let mul x y = x * y;;
let f () =
let a = add 1 2 in
[|(λv.λv2.v2) ((λv.v v) (λv.v v))|] | |
1. app2 -> λk1.[|λv.λv2.v2|] (λf1.[|(λv.v v) (λv.v v)|] (λa1.f1 a1 k1)) | |
2. lam -> λk1.(λk2.k2 (λv.[|λv2.v2|])) (λf1.[|(λv.v v) (λv.v v)|] (λa1.f1 a1 k1)) | |
3. lam -> λk1.(λk2.k2 (λv.(λk3.k3 (λv2.[|v2|])))) (λf1.[|(λv.v v) (λv.v v)|] (λa1.f1 a1 k1)) | |
4. val -> λk1.(λk2.k2 (λv.(λk3.k3 (λv2.(λk4.k4 v2))))) (λf1.[|(λv.v v) (λv.v v)|] (λa1.f1 a1 k1)) | |
5. app2 -> λk1.(λk2.k2 (λv.(λk3.k3 (λv2.(λk4.k4 v2))))) (λf1.(λk5.[|λv.v v|] (λf5.[|λv.v v|] (λa5.f5 a5 k5))) (λa1.f1 a1 k1)) | |
6. lam -> λk1.(λk2.k2 (λv.(λk3.k3 (λv2.(λk4.k4 v2))))) (λf1.(λk5.(λk6.k6 (λv.[|v v|])) (λf5.[|λv.v v|] (λa5.f5 a5 k5))) (λa1.f1 a1 k1)) | |
7. app2 -> λk1.(λk2.k2 (λv.(λk3.k3 (λv2.(λk4.k4 v2))))) (λf1.(λk5.(λk6.k6 (λv.(λk7.[|v|] (λf7.[|v|] (λa7.f7 a7 k7))))) (λf5.[|λv.v v|] (λa5.f5 a5 k5))) (λa1.f1 a1 k1)) | |
8. val -> λk1.(λk2.k2 (λv.(λk3.k3 (λv2.(λk4.k4 v2))))) (λf1.(λk5.(λk6.k6 (λv.(λk7.(λk8.k8 v) (λf7.[|v|] (λa7.f7 a7 k7))))) (λf5.[|λv.v v|] (λa5.f5 a5 k5))) (λa1.f1 a1 k1)) | |
9. val -> λk1.(λk2.k2 (λv.(λk3.k3 ( |
[| x |] = λk.k x ・・・val
[| λx.t |] = λk.k (λx.[|t|]) ・・・lam
[| π t |] = λk.[|t|] (λa.k (π a)) ・・・app1
[| t1 t2 |] = λk.[|t1|] (λf.[|t2|] (λa.f a k)) ・・・app2
[| π t1 t2 |] = λk.[|t1|] (λa.[|t2|] (λb.k (π a b)))・・・app3
[| Sx.t |] = λk.[x↦λa.λk'.k' (k a)]([|t|] (λv.v))・・・shift
[| <t> |] = λk.k ([|t|] (λv.v)) ・・・reset
[|<concat (Sk.λx.k x) (Sk.λx.k (i2s x))> "a" 10|]
[| x |] = λk.k x ・・・val
[| λx.t |] = λk.k (λx.[|t|]) ・・・lam
[| π t |] = λk.[|t|] (λa.k (π a)) ・・・app1
[| t1 t2 |] = λk.[|t1|] (λf.[|t2|] (λa.f a k)) ・・・app2
[| Sx.t |] = λk.[x↦λa.λk'.k' (k a)]([|t|] (λv.v))・・・shift
[| <t> |] = λk.k ([|t|] (λv.v)) ・・・reset
変換対象: <add10 (Sx.x (x 100))>
type CommandInfo = | |
{ Names: string[] | |
Summary: string | |
Syntax: string | |
Help: string option } | |
type CommandWrapper(info: CommandInfo, proc: string -> unit) = | |
inherit Command() | |
override __.Names = info.Names |
#!/bin/sh | |
msg=${1:-"first commit"} | |
git init | |
tree_hash=$(git write-tree) | |
commit_hash=$(echo -n "$msg" | git commit-tree $tree_hash) | |
echo $commit_hash > .git/refs/heads/master |
In the language specification, the translation rule of do! e;
is defined as follows:
T(do! e;, V, C, q) = T(let! () = src(e) in b.Return(), V, C, q)
And the signature of Return
is usually 'a -> M<'a>
, so the type of do! e;
results M<unit>
.
//// シャドーイングの例 | |
// これは無限ループ | |
let x = 0 | |
while x < 10 do // ここでのxは常に最初のx | |
let x = x + 1 // 新しいxのスコープはwhileの本体のみで有効 | |
printfn "%d" x | |
//// 再代入の例 |
open System.Collections.Generic | |
type CollectionBuilder< 'TCollection, 'TElem, 'TRet when 'TCollection : (member Add : 'TElem -> 'TRet)> () = | |
[<DefaultValue>] val mutable xs : 'TCollection | |
member inline this.Yield(x: 'TElem) = | |
(^TCollection : (member Add : 'TElem -> 'TRet) (this.xs, x)) |> ignore | |
member inline this.Delay(f) = f | |
member inline this.Combine(_, rest) = rest () | |
member inline this.Run(f) = f (); this.xs | |
member inline this.Zero() = () |
//================================================================================ | |
// 共通 | |
//================================================================================ | |
type EmailAddress = | |
{ EAValue: string } | |
type SurfaceAddress = | |
{ SAValue: string } | |
type Customer = |