taiki45
May 11, 2014
900

# Haskell でつくる VM 〜散りゆく Endomorphism〜

May 11, 2014

## Transcript

ʙࢄΓΏ͘ Endomorphisʙ
taiki45

2. ϓϩάϥϛϯάྺ2೥൒ͷ

3. ϖϧγΞޠ͠Ό΂Δ

4. ͓͔͞ͳ

5. ε( ε^o^)э

6. hs-vm
Simple Virtual Machine written in Haskell.
!
https://github.com/taiki45/hs-vm

7. Why VM

8. ܭࢉػͷ
ιϑτ΢ΣΞ࣮૷

9. Register Machine
vs
Stack Machine

10. hs-vm has no StateT

11. Endomorphism

12. Endomorphism
A
࢝ҬͱऴҬ͕ಉ͡୅਺ܥͰ͋ΔΑ͏ͳ४ಉܕࣸ૾

13. Endomorphism
A
࢝ҬͱऴҬ͕ಉ͡ू߹Ͱ͋ΔΑ͏ͳؔ਺

14. VM ͱ໋ྩ
V
͋ΔVMΛߟ͑Δ
ͦͷVM͕ͱΔঢ়ଶͷू߹Λ V ͱ͢Δ
[1,2]
[3]
[3,4,5]

15. VM ͱ໋ྩ
V
[3,4]
[1,2,4]

16. VM ͱ໋ྩ
VM ͷ໋ྩ͸ Endomorphism ͱߟ͑ΒΕΔ
V

17. ໋ྩͷ߹੒

18. Monoid (M, ŋ)
m ŋ i = m = i ŋ m
m ŋ (m ŋ m) = (m ŋ m) ŋ m

19. ਖ਼ͷ੔਺ (N, ×)
3 × 1 = 3 = 3 × 1
3 × (4 × 5) = (3 × 4) × 5

20. Ϧετ (L, ++)
[1, 2] ++ [] = [1, 2] = [] ++ [1, 2]
[1] ++ ([2] ++ [3]) = ([1] ++ [2]) ++ [3]

21. Endomorphism as Monoid
A
id
f
g
f . id = f = id . f
(h . g) . f = h . (g . f)
h

22. VM ͱ໋ྩ
V
f f: VM → VM
f: ॳظঢ়ଶ → ऴྃঢ়ଶ

23. VM ͷ࣮ߦͱ͸

24. ͻͱͭͷࣸ૾Λ
୳͢͜ͱͩͬͨΜͩʂ

25. ͋Γ͠೔ͷ VM ͷ࣮ߦ
Dual ͸૒ର
Endo ͷ૒ର͸ͦͷ߹੒ॱং͕ٯ
144c3a3dbdb

26. ৚݅δϟϯϓ

27. ݱࡏͷ VM ࣮ߦ
V
Endo Λॱ࣍ద༻͍ͯ͘͠ελΠϧ
࣍ʹద༻͢Δࣸ૾Λ program counter Λ΋ͱʹ୳͢

28. ֶͼ
• ػցޠ(ΞηϯϒϦݴޠ)ͱͷରԠ
• call convention