SlideShare a Scribd company logo

LLDN / キミならどう書く Haskell 編 (規定演技)

2005年のLLDNでの発表資料。

1 of 15
Download to read offline
君ならどう書く - Haskell –
       規定演技編
             酒井 政裕
トピック

パーサ
  パーサ・コンビネータ
  漢数字のパーサ
  式のパーサ
式の評価
まとめ
パーサ・コンビネータ

パーサを定義し、また単純なパーサからより
複雑なパーサを定義するための一連の関数。
EDSL(Embeded Domain Specific
Language)の典型的な例。
 BNF風の表記がそのままプログラムに!?
実装は色々あるけど、今回は自前で実装。
パーサ・コンビネータ (cont’d)
式          言語       説明
return a            常に成功しaを返すパーサ
           ε
p <|> q    p|q      pとqの選択
mzero      ∅        常に失敗するパーサ
char c     {c}      文字cを受理するパーサ
string s   {s}      文字列sを受理するパーサ
p >>= f    p f(x)   pとf(x)の連接 (xはpのパース結果)
p >> q     pq       pとqの連接
many p     p*       0回以上の繰り返し
モナド(Monad)

 compuatationを抽象化するインターフェース
  普通の計算だけでなく、色々な計算(「例外」「副作
  用」「非決定性」があったり無かったりとか)を統一し
  て扱いたい。
  元々は圏論の概念だけど、それはどうでもいい。
 このパーサコンビネータもモナドになっている
  returnと(>>=)が存在してある法則を満たす。
  既存のライブラリと糖衣構文(do記法)が使える。
漢数字のパーサ

最初に考えた文法
 number ::= n1
 n1 ::= n2 | n2? “無量大数” n2?
 n2 ::= n3 | n3? “不可思議” n3?
 …
 nn ::= digit
効率が悪い

Recommended

LLDN / キミならどう書く Haskell 編 (自由演技)
LLDN / キミならどう書く Haskell 編 (自由演技)LLDN / キミならどう書く Haskell 編 (自由演技)
LLDN / キミならどう書く Haskell 編 (自由演技)Masahiro Sakai
 
Trabajo ii de estadistica
Trabajo ii de estadisticaTrabajo ii de estadistica
Trabajo ii de estadisticaRima Bouchacra
 
Lataif e ashrafi malfoozat e syed makhdoom ashraf 60
Lataif e ashrafi malfoozat e syed makhdoom ashraf 60Lataif e ashrafi malfoozat e syed makhdoom ashraf 60
Lataif e ashrafi malfoozat e syed makhdoom ashraf 60Aale Rasool Ahmad
 
راہ خدا عزوجل میں خرچ کرنے کے فضائل
راہ خدا عزوجل میں خرچ کرنے کے فضائلراہ خدا عزوجل میں خرچ کرنے کے فضائل
راہ خدا عزوجل میں خرچ کرنے کے فضائلdawateislami
 
Nija daivashakthi - May 2013
Nija daivashakthi - May 2013Nija daivashakthi - May 2013
Nija daivashakthi - May 2013Shalem Arasavelli
 

More Related Content

What's hot

Friday Sermon Delivered by Hazrat Mirza Nasir Ahmed (RA) 05 July1974
Friday Sermon Delivered by Hazrat Mirza Nasir Ahmed (RA) 05 July1974Friday Sermon Delivered by Hazrat Mirza Nasir Ahmed (RA) 05 July1974
Friday Sermon Delivered by Hazrat Mirza Nasir Ahmed (RA) 05 July1974muzaffertahir9
 
Benamazi ka anjam by maulana shakir ali noori
Benamazi ka anjam by maulana shakir ali nooriBenamazi ka anjam by maulana shakir ali noori
Benamazi ka anjam by maulana shakir ali nooriAtaurrahman Noori
 
187 Takhlees Usoo Le Shashi - brelvi madaris
187 Takhlees Usoo Le Shashi - brelvi madaris187 Takhlees Usoo Le Shashi - brelvi madaris
187 Takhlees Usoo Le Shashi - brelvi madarisnabeelsahab
 
Hazrat Khalid Bin Waleed Book By Ataurrahman Noori
Hazrat Khalid Bin Waleed Book By Ataurrahman NooriHazrat Khalid Bin Waleed Book By Ataurrahman Noori
Hazrat Khalid Bin Waleed Book By Ataurrahman NooriAtaurrahman Noori
 
Faiz e alam december 2015
Faiz e alam december 2015Faiz e alam december 2015
Faiz e alam december 2015Muhammad Tariq
 
قرار دینا صرف اللہ کا کام ہے - خطبہ جمعہ - 8 مئی 1981متقی اورمطہر
قرار دینا صرف اللہ کا کام ہے - خطبہ جمعہ - 8 مئی 1981متقی اورمطہر قرار دینا صرف اللہ کا کام ہے - خطبہ جمعہ - 8 مئی 1981متقی اورمطہر
قرار دینا صرف اللہ کا کام ہے - خطبہ جمعہ - 8 مئی 1981متقی اورمطہر muzaffertahir9
 
Al Fazl International - weekly 19 September 2014
Al Fazl International - weekly 19 September 2014Al Fazl International - weekly 19 September 2014
Al Fazl International - weekly 19 September 2014muzaffertahir9
 
اعلٰحضرت (رحمۃ اللہ علیہ) کی انفرادی کوششیں
اعلٰحضرت (رحمۃ اللہ علیہ) کی انفرادی کوششیںاعلٰحضرت (رحمۃ اللہ علیہ) کی انفرادی کوششیں
اعلٰحضرت (رحمۃ اللہ علیہ) کی انفرادی کوششیںIlyas Qadri Ziaee
 
A Life in the Day of Hazrat Mirza Tahir Ahmad (RA) Kahalifa tul Masih the 4th
A Life in the Day of Hazrat Mirza Tahir Ahmad (RA) Kahalifa tul Masih the 4thA Life in the Day of Hazrat Mirza Tahir Ahmad (RA) Kahalifa tul Masih the 4th
A Life in the Day of Hazrat Mirza Tahir Ahmad (RA) Kahalifa tul Masih the 4thmuzaffertahir9
 
کربلا کا خونیں منظر
کربلا کا خونیں منظرکربلا کا خونیں منظر
کربلا کا خونیں منظرIlyas Qadri Ziaee
 
The tabernacle of Moses (Telugu)
The tabernacle of Moses (Telugu)The tabernacle of Moses (Telugu)
The tabernacle of Moses (Telugu)Shalem Arasavelli
 
Lataif e ashrafi malfoozat e syed makhdoom ashraf 54
Lataif e ashrafi malfoozat e syed makhdoom ashraf 54Lataif e ashrafi malfoozat e syed makhdoom ashraf 54
Lataif e ashrafi malfoozat e syed makhdoom ashraf 54Aale Rasool Ahmad
 

What's hot (17)

Friday Sermon Delivered by Hazrat Mirza Nasir Ahmed (RA) 05 July1974
Friday Sermon Delivered by Hazrat Mirza Nasir Ahmed (RA) 05 July1974Friday Sermon Delivered by Hazrat Mirza Nasir Ahmed (RA) 05 July1974
Friday Sermon Delivered by Hazrat Mirza Nasir Ahmed (RA) 05 July1974
 
Benamazi ka anjam by maulana shakir ali noori
Benamazi ka anjam by maulana shakir ali nooriBenamazi ka anjam by maulana shakir ali noori
Benamazi ka anjam by maulana shakir ali noori
 
187 Takhlees Usoo Le Shashi - brelvi madaris
187 Takhlees Usoo Le Shashi - brelvi madaris187 Takhlees Usoo Le Shashi - brelvi madaris
187 Takhlees Usoo Le Shashi - brelvi madaris
 
Ganesha manasapuja
Ganesha manasapujaGanesha manasapuja
Ganesha manasapuja
 
039 az-zumar
039 az-zumar039 az-zumar
039 az-zumar
 
My manasapuja
My manasapujaMy manasapuja
My manasapuja
 
Hazrat Khalid Bin Waleed Book By Ataurrahman Noori
Hazrat Khalid Bin Waleed Book By Ataurrahman NooriHazrat Khalid Bin Waleed Book By Ataurrahman Noori
Hazrat Khalid Bin Waleed Book By Ataurrahman Noori
 
Faiz e alam december 2015
Faiz e alam december 2015Faiz e alam december 2015
Faiz e alam december 2015
 
قرار دینا صرف اللہ کا کام ہے - خطبہ جمعہ - 8 مئی 1981متقی اورمطہر
قرار دینا صرف اللہ کا کام ہے - خطبہ جمعہ - 8 مئی 1981متقی اورمطہر قرار دینا صرف اللہ کا کام ہے - خطبہ جمعہ - 8 مئی 1981متقی اورمطہر
قرار دینا صرف اللہ کا کام ہے - خطبہ جمعہ - 8 مئی 1981متقی اورمطہر
 
Al Fazl International - weekly 19 September 2014
Al Fazl International - weekly 19 September 2014Al Fazl International - weekly 19 September 2014
Al Fazl International - weekly 19 September 2014
 
اعلٰحضرت (رحمۃ اللہ علیہ) کی انفرادی کوششیں
اعلٰحضرت (رحمۃ اللہ علیہ) کی انفرادی کوششیںاعلٰحضرت (رحمۃ اللہ علیہ) کی انفرادی کوششیں
اعلٰحضرت (رحمۃ اللہ علیہ) کی انفرادی کوششیں
 
A Life in the Day of Hazrat Mirza Tahir Ahmad (RA) Kahalifa tul Masih the 4th
A Life in the Day of Hazrat Mirza Tahir Ahmad (RA) Kahalifa tul Masih the 4thA Life in the Day of Hazrat Mirza Tahir Ahmad (RA) Kahalifa tul Masih the 4th
A Life in the Day of Hazrat Mirza Tahir Ahmad (RA) Kahalifa tul Masih the 4th
 
Shikshapatri
ShikshapatriShikshapatri
Shikshapatri
 
کربلا کا خونیں منظر
کربلا کا خونیں منظرکربلا کا خونیں منظر
کربلا کا خونیں منظر
 
The tabernacle of Moses (Telugu)
The tabernacle of Moses (Telugu)The tabernacle of Moses (Telugu)
The tabernacle of Moses (Telugu)
 
Micoses superficiais
Micoses superficiaisMicoses superficiais
Micoses superficiais
 
Lataif e ashrafi malfoozat e syed makhdoom ashraf 54
Lataif e ashrafi malfoozat e syed makhdoom ashraf 54Lataif e ashrafi malfoozat e syed makhdoom ashraf 54
Lataif e ashrafi malfoozat e syed makhdoom ashraf 54
 

More from Masahiro Sakai

DeepXplore: Automated Whitebox Testing of Deep Learning
DeepXplore: Automated Whitebox Testing of Deep LearningDeepXplore: Automated Whitebox Testing of Deep Learning
DeepXplore: Automated Whitebox Testing of Deep LearningMasahiro Sakai
 
Towards formal verification of neural networks
Towards formal verification of neural networksTowards formal verification of neural networks
Towards formal verification of neural networksMasahiro Sakai
 
関数プログラマから見たPythonと機械学習
関数プログラマから見たPythonと機械学習関数プログラマから見たPythonと機械学習
関数プログラマから見たPythonと機械学習Masahiro Sakai
 
Writing a SAT solver as a hobby project
Writing a SAT solver as a hobby projectWriting a SAT solver as a hobby project
Writing a SAT solver as a hobby projectMasahiro Sakai
 
RClassify: Classifying Race Conditions in Web Applications via Deterministic ...
RClassify: Classifying Race Conditions in Web Applications via Deterministic ...RClassify: Classifying Race Conditions in Web Applications via Deterministic ...
RClassify: Classifying Race Conditions in Web Applications via Deterministic ...Masahiro Sakai
 
SAT/SMT solving in Haskell
SAT/SMT solving in HaskellSAT/SMT solving in Haskell
SAT/SMT solving in HaskellMasahiro Sakai
 
SAT/SMTソルバの仕組み
SAT/SMTソルバの仕組みSAT/SMTソルバの仕組み
SAT/SMTソルバの仕組みMasahiro Sakai
 
Introduction to Max-SAT and Max-SAT Evaluation
Introduction to Max-SAT and Max-SAT EvaluationIntroduction to Max-SAT and Max-SAT Evaluation
Introduction to Max-SAT and Max-SAT EvaluationMasahiro Sakai
 
Aluminum: Principled Scenario Exploration through Minimality
Aluminum: Principled Scenario Exploration through MinimalityAluminum: Principled Scenario Exploration through Minimality
Aluminum: Principled Scenario Exploration through MinimalityMasahiro Sakai
 
代数的実数とCADの実装紹介
代数的実数とCADの実装紹介代数的実数とCADの実装紹介
代数的実数とCADの実装紹介Masahiro Sakai
 
How a CDCL SAT solver works
How a CDCL SAT solver worksHow a CDCL SAT solver works
How a CDCL SAT solver worksMasahiro Sakai
 
萩野服部研究室 スキー合宿 2012 自己紹介(酒井)
萩野服部研究室 スキー合宿 2012 自己紹介(酒井)萩野服部研究室 スキー合宿 2012 自己紹介(酒井)
萩野服部研究室 スキー合宿 2012 自己紹介(酒井)Masahiro Sakai
 
自動定理証明の紹介
自動定理証明の紹介自動定理証明の紹介
自動定理証明の紹介Masahiro Sakai
 
“Adoption and Focus: Practical Linear Types for Imperative Programming”他の紹介@P...
“Adoption and Focus: Practical Linear Types for Imperative Programming”他の紹介@P...“Adoption and Focus: Practical Linear Types for Imperative Programming”他の紹介@P...
“Adoption and Focus: Practical Linear Types for Imperative Programming”他の紹介@P...Masahiro Sakai
 
“Design and Implementation of Generics for the .NET Common Language Runtime”他...
“Design and Implementation of Generics for the .NET Common Language Runtime”他...“Design and Implementation of Generics for the .NET Common Language Runtime”他...
“Design and Implementation of Generics for the .NET Common Language Runtime”他...Masahiro Sakai
 
Relaxed Dependency Analysis
Relaxed Dependency AnalysisRelaxed Dependency Analysis
Relaxed Dependency AnalysisMasahiro Sakai
 
“Symbolic bounds analysis of pointers, array indices, and accessed memory reg...
“Symbolic bounds analysis of pointers, array indices, and accessed memory reg...“Symbolic bounds analysis of pointers, array indices, and accessed memory reg...
“Symbolic bounds analysis of pointers, array indices, and accessed memory reg...Masahiro Sakai
 
自然言語をラムダ式で解釈する体系PTQのHaskell実装
自然言語をラムダ式で解釈する体系PTQのHaskell実装自然言語をラムダ式で解釈する体系PTQのHaskell実装
自然言語をラムダ式で解釈する体系PTQのHaskell実装Masahiro Sakai
 

More from Masahiro Sakai (20)

DeepXplore: Automated Whitebox Testing of Deep Learning
DeepXplore: Automated Whitebox Testing of Deep LearningDeepXplore: Automated Whitebox Testing of Deep Learning
DeepXplore: Automated Whitebox Testing of Deep Learning
 
Towards formal verification of neural networks
Towards formal verification of neural networksTowards formal verification of neural networks
Towards formal verification of neural networks
 
関数プログラマから見たPythonと機械学習
関数プログラマから見たPythonと機械学習関数プログラマから見たPythonと機械学習
関数プログラマから見たPythonと機械学習
 
Writing a SAT solver as a hobby project
Writing a SAT solver as a hobby projectWriting a SAT solver as a hobby project
Writing a SAT solver as a hobby project
 
RClassify: Classifying Race Conditions in Web Applications via Deterministic ...
RClassify: Classifying Race Conditions in Web Applications via Deterministic ...RClassify: Classifying Race Conditions in Web Applications via Deterministic ...
RClassify: Classifying Race Conditions in Web Applications via Deterministic ...
 
ゼロピッチ: MOOC
ゼロピッチ: MOOCゼロピッチ: MOOC
ゼロピッチ: MOOC
 
SAT/SMT solving in Haskell
SAT/SMT solving in HaskellSAT/SMT solving in Haskell
SAT/SMT solving in Haskell
 
SAT/SMTソルバの仕組み
SAT/SMTソルバの仕組みSAT/SMTソルバの仕組み
SAT/SMTソルバの仕組み
 
Introduction to Max-SAT and Max-SAT Evaluation
Introduction to Max-SAT and Max-SAT EvaluationIntroduction to Max-SAT and Max-SAT Evaluation
Introduction to Max-SAT and Max-SAT Evaluation
 
Aluminum: Principled Scenario Exploration through Minimality
Aluminum: Principled Scenario Exploration through MinimalityAluminum: Principled Scenario Exploration through Minimality
Aluminum: Principled Scenario Exploration through Minimality
 
代数的実数とCADの実装紹介
代数的実数とCADの実装紹介代数的実数とCADの実装紹介
代数的実数とCADの実装紹介
 
How a CDCL SAT solver works
How a CDCL SAT solver worksHow a CDCL SAT solver works
How a CDCL SAT solver works
 
Omega test and beyond
Omega test and beyondOmega test and beyond
Omega test and beyond
 
萩野服部研究室 スキー合宿 2012 自己紹介(酒井)
萩野服部研究室 スキー合宿 2012 自己紹介(酒井)萩野服部研究室 スキー合宿 2012 自己紹介(酒井)
萩野服部研究室 スキー合宿 2012 自己紹介(酒井)
 
自動定理証明の紹介
自動定理証明の紹介自動定理証明の紹介
自動定理証明の紹介
 
“Adoption and Focus: Practical Linear Types for Imperative Programming”他の紹介@P...
“Adoption and Focus: Practical Linear Types for Imperative Programming”他の紹介@P...“Adoption and Focus: Practical Linear Types for Imperative Programming”他の紹介@P...
“Adoption and Focus: Practical Linear Types for Imperative Programming”他の紹介@P...
 
“Design and Implementation of Generics for the .NET Common Language Runtime”他...
“Design and Implementation of Generics for the .NET Common Language Runtime”他...“Design and Implementation of Generics for the .NET Common Language Runtime”他...
“Design and Implementation of Generics for the .NET Common Language Runtime”他...
 
Relaxed Dependency Analysis
Relaxed Dependency AnalysisRelaxed Dependency Analysis
Relaxed Dependency Analysis
 
“Symbolic bounds analysis of pointers, array indices, and accessed memory reg...
“Symbolic bounds analysis of pointers, array indices, and accessed memory reg...“Symbolic bounds analysis of pointers, array indices, and accessed memory reg...
“Symbolic bounds analysis of pointers, array indices, and accessed memory reg...
 
自然言語をラムダ式で解釈する体系PTQのHaskell実装
自然言語をラムダ式で解釈する体系PTQのHaskell実装自然言語をラムダ式で解釈する体系PTQのHaskell実装
自然言語をラムダ式で解釈する体系PTQのHaskell実装
 

LLDN / キミならどう書く Haskell 編 (規定演技)