Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
ラムダ計算に基づいた純粋関数型言語の実装 ~パーサーコンビネータを使ってみる~ #TechLunch
Search
Livesense Inc.
PRO
April 23, 2014
Technology
0
180
ラムダ計算に基づいた純粋関数型言語の実装 ~パーサーコンビネータを使ってみる~ #TechLunch
2011/05/18(水) @ Livesense TechLunch
発表者:塩足 拓也
Livesense Inc.
PRO
April 23, 2014
Tweet
Share
More Decks by Livesense Inc.
See All by Livesense Inc.
EM候補者向け転職会議説明資料
livesense
PRO
0
6
コロナで失われたノベルティ作成ノウハウを復活させた話
livesense
PRO
0
73
株式会社リブセンス 会社説明資料(報道関係者様向け)
livesense
PRO
0
360
転職会議でGPT-3を活用した企業口コミ要約機能をリリースした話
livesense
PRO
0
1.1k
株式会社リブセンス マッハバイト_プレイブック
livesense
PRO
0
420
Tech Award 2021 選出方法
livesense
PRO
0
1k
株式会社リブセンス エンジニアリング組織を支える風土と制度
livesense
PRO
0
530
株式会社リブセンス・マッハバイト 採用候補者様向け資料
livesense
PRO
0
210
株式会社リブセンス・転職会議 採用候補者様向け資料
livesense
PRO
0
2k
Other Decks in Technology
See All in Technology
Building a RAG-poweredAI chat appwith Python and VS Code
pamelafox
0
140
Autonomous Database Cloud 技術詳細 / adb-s_technical_detail_jp
oracle4engineer
PRO
14
35k
JAWS-UG Bedrock Claude Night
yamahiro
3
690
AOAI をきっかけに 社内の Azure 管理を見直した話
recruitengineers
PRO
1
430
AWS学習者向けにAzureの解説スライドを作成した話
handy
3
160
データベース02: データベースの概念
trycycle
0
180
Babylon.jsと色々なものを組み合わせる:ブラウザのAPIやガジェットや2D描画ライブラリなど / Babylon.js 勉強会 vol.3
you
PRO
0
150
「スニダン」開発組織の構造に込めた意図 ~組織作りはパッションや政治ではない!~
rinchsan
4
610
Cloud Service Mesh に触れ合う
phaya72
1
120
How to do well in consulting–Balkan Ruby 2024
irinanazarova
0
120
.NET Profiler in 2024.
kkamegawa
2
810
JSON攻略法.pdf
miyakemito
8
5.2k
Featured
See All Featured
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
14
1.5k
Automating Front-end Workflow
addyosmani
1357
200k
The Language of Interfaces
destraynor
151
23k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
188
16k
GraphQLとの向き合い方2022年版
quramy
33
12k
Intergalactic Javascript Robots from Outer Space
tanoku
266
26k
The Straight Up "How To Draw Better" Workshop
denniskardys
228
130k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
352
28k
A Philosophy of Restraint
colly
197
16k
We Have a Design System, Now What?
morganepeng
44
6.8k
Building Effective Engineering Teams - LeadDev
addyosmani
31
1.9k
How STYLIGHT went responsive
nonsquared
92
4.8k
Transcript
ラムダ計算に基づいた純粋関数型 言語の実装 2011/05/18 Takuya Shiotari ~パーサーコンビネータを使ってみる~
AGENDA ¢ Abstrac,on ¢ Design policy ¢ Programming
Language & Compiler ¢ Func,onal Language ¢ What’s Lambda calculus? ¢ Parser Combinator ¢ rparsec
ABSTRACTION 動機 目的 ラムダ計算に基づいたプログラミング言語の設計・実装を行う なんか関数型言語って流行っぽい… んで、その関数型言語でパーサーコンビネータってのがおもろいらしい… おっしゃー!やってみるか!! やるんだったら言語作りたいよね でも、あんまり実用的な言語意識しすぎると設計で終わっちゃいそうだなぁ…
じゃ、超シンプルな言語仕様で実装しよう!!!!
DESIGN POLICY ¢ 実装言語はRuby ¢ インタプリタとして実装 ¢ 実装を単純化するためにIO等は実装しない
¢ パフォーマンスは一切考えない ¢ 文法はLisp-‐Like ¢ Scanner/ParserはParser Combinatorで実装する
PROGRAMMING LANGUAGE & COMPILER 別紙
FUNCTIONAL LANGUAGE 純粋関数型言語 ¢ Haskell、Concurrent Clean、Miranda
非純粋関数型言語 ¢ ML、Lisp、Scheme、OCaml、F# ラムダ計算の概念に基づいたプログラミング言語 特徴 第一級関数(First class func,on) 副作用(side effects)なし カリー化(carrying) 遅延評価(lazy evalua,on) 代表的な言語
関数の定義と実行を抽象化した計算モデル WHAT’S LAMBDA CALCULUS? <expr> ::= <iden,fier>
| (“λ” <iden,fier> “.” <expr>) | (<expr> <expr>) 例 f(x) = x + 1 λ.x x+1 変数 ラムダ抽象 関数適用 ラムダ抽象 f(2) (λ.x x+1) 2 関数適用
PARSER COMBINATOR ¢ 最近流行のトップダウン構文解析 ¢ 基本的なアイデアはパーサを結合子で合成して複雑な パーサを生成 ¢
BNFからコードに落とし込むのが簡単 ¢ 実装と文法定義で言語にギャップレス ¢ ScannerとParserでギャップレス
RPARSEC require 'rubygems' require 'rparsec' include RParsec::Parsers
eol = string ?\n quoted_char = not_char(?") | string('""') >> value(?") quoted_cell = char(?") >> quoted_char.many.bind { |s| value(s.join('')) } << char(?") cell = quoted_cell | regexp(/[^,"\n]*/) line = cell.separated(char(?,)) csv_file = (line << eol).many csvパーサ
RPARSEC require 'rubygems' require 'rparsec' include RParsec::Parsers
include RParsec::Functors ops = RParsec::OperatorTable.new do |tbl| tbl.infixl(string(?+) >> Plus, 10) tbl.infixl(string(?-‐) >> Minus, 10) tbl.infixl(string(?*) >> Mul, 20) tbl.infixl(string(?/) >> Div, 20) tbl.prefix(string(?-‐) >> Neg, 50) end expr = nil term = integer.map(&To_i) | string(?() >> lazy { expr } << string(?)) delim = whitespace.many_ expr = delim >> RParsec::Expressions.build(term, ops, delim) calc
次回予告 ¢ ラムダ計算の実装 ¢ ラムダ式を用いて自然数を定義(チャーチ数) 0 := λf x.
x 1 := λf x. f x 2 := λf x. f (f x) 3 := λf x. f (f (f x))