SlideShare a Scribd company logo
1 of 7
Download to read offline
Relaxed Dependency Analysis

    〜Haskell 2009年末の集い〜
            酒井 政裕
⾃⼰紹介

  酒井 政裕
• Blog: ヒビルテ
• Twitter: @masahiro_sakai

• 2001年末ごろにHaskellに遭遇
• 好きな関数: unfoldr
背景: Haskellの型推論の流れ
• 依存関係(の強連結成分)で定義をグループ化
• 末端のグループから順に型推論
• 例: 以下では b, c の型をまず推論し、その
  結果を使って a の型を推論
 –a=…b…
                a
 –b=…c…
 –c=…b…

                b      c
Relaxed Dependency Analysis
• 依存関係の定義の変更
 – Haskell98では、aがbを参照していれば、
   aはbに依存していた
 – Haskell2010では、bに型宣⾔がある場合には、
   aがbを参照していても、依存とはみなさない
• 効果
 – より多相的な型を推論出来るようになる
 – これまで型宣⾔が必要だったのが、不要にな
   ることがある
例: Haskell98の場合
                         • fとgは相互に依存してい
f :: Eq a ⇒ a → Bool       るので、同時に型推論
f x = (x == x)
     ∨ g True               f               g
     ∨ g “Yes”

g y = (y ≤ y) ∨ f True   • g が⼆通りの型で使われ
                           ている
                          – Bool → Bool
                          – String → Bool
                         • ⇒ 型エラー
例: Haskell2010の場合
                         • fには型宣⾔があるので、
f :: Eq a ⇒ a → Bool       gはfには依存しない
f x = (x == x)
     ∨ g True
     ∨ g “Yes”                f             g

                                     ×
g y = (y ≤ y) ∨ f True
                         • gを先に型推論して、
                           g :: ∀a. Ord a ⇒ a → Bool
                         • fの型推論では、gの型変数
                           aをBoolとStringに具体化
何が起こっているのか?
• Haskellの基づいているHindley-Milnerのアルゴ
  リズムでは、ある定義グループの型推論の最後
  の段階で型を多相的にする。

• なので、先に型推論が済んでいる部分は、型が
  多相的な型になっているので、それを任意に具
  体化出来る。
• ⼀⽅、型推論中の部分は、型が多相的になって
  いないので、複数の型で使うことが出来ない。

More Related Content

Viewers also liked

Formal methods20100529
Formal methods20100529Formal methods20100529
Formal methods20100529tmiya
 
“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
 
Run-time Code Generation and Modal-ML の紹介@PLDIr#2
Run-time Code Generation and Modal-ML の紹介@PLDIr#2Run-time Code Generation and Modal-ML の紹介@PLDIr#2
Run-time Code Generation and Modal-ML の紹介@PLDIr#2Masahiro 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
 
Introduction to Categorical Programming (Revised)
Introduction to Categorical Programming (Revised)Introduction to Categorical Programming (Revised)
Introduction to Categorical Programming (Revised)Masahiro Sakai
 
Introduction to Categorical Programming
Introduction to Categorical ProgrammingIntroduction to Categorical Programming
Introduction to Categorical ProgrammingMasahiro Sakai
 
自然言語をラムダ式で解釈する体系PTQのHaskell実装
自然言語をラムダ式で解釈する体系PTQのHaskell実装自然言語をラムダ式で解釈する体系PTQのHaskell実装
自然言語をラムダ式で解釈する体系PTQのHaskell実装Masahiro Sakai
 

Viewers also liked (8)

Formal methods20100529
Formal methods20100529Formal methods20100529
Formal methods20100529
 
“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”他...
 
Run-time Code Generation and Modal-ML の紹介@PLDIr#2
Run-time Code Generation and Modal-ML の紹介@PLDIr#2Run-time Code Generation and Modal-ML の紹介@PLDIr#2
Run-time Code Generation and Modal-ML の紹介@PLDIr#2
 
“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...
 
Introduction to Categorical Programming (Revised)
Introduction to Categorical Programming (Revised)Introduction to Categorical Programming (Revised)
Introduction to Categorical Programming (Revised)
 
Introduction to Categorical Programming
Introduction to Categorical ProgrammingIntroduction to Categorical Programming
Introduction to Categorical Programming
 
自然言語をラムダ式で解釈する体系PTQのHaskell実装
自然言語をラムダ式で解釈する体系PTQのHaskell実装自然言語をラムダ式で解釈する体系PTQのHaskell実装
自然言語をラムダ式で解釈する体系PTQのHaskell実装
 

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
 
Whole Program Paths 等の紹介@PLDIr#3
Whole Program Paths 等の紹介@PLDIr#3Whole Program Paths 等の紹介@PLDIr#3
Whole Program Paths 等の紹介@PLDIr#3Masahiro Sakai
 
融合変換による最適化の理論的基盤と正当性 (2006-06-27)
融合変換による最適化の理論的基盤と正当性 (2006-06-27)融合変換による最適化の理論的基盤と正当性 (2006-06-27)
融合変換による最適化の理論的基盤と正当性 (2006-06-27)Masahiro Sakai
 
融合変換による最適化の理論的基盤と正当性 (2006-06-20)
融合変換による最適化の理論的基盤と正当性 (2006-06-20)融合変換による最適化の理論的基盤と正当性 (2006-06-20)
融合変換による最適化の理論的基盤と正当性 (2006-06-20)Masahiro Sakai
 
Ruby-GNOME2におけるGC問題
Ruby-GNOME2におけるGC問題Ruby-GNOME2におけるGC問題
Ruby-GNOME2におけるGC問題Masahiro Sakai
 
LLW2004 その場でどう書く - Haskell
LLW2004 その場でどう書く - HaskellLLW2004 その場でどう書く - Haskell
LLW2004 その場でどう書く - HaskellMasahiro 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 自己紹介(酒井)
 
自動定理証明の紹介
自動定理証明の紹介自動定理証明の紹介
自動定理証明の紹介
 
Whole Program Paths 等の紹介@PLDIr#3
Whole Program Paths 等の紹介@PLDIr#3Whole Program Paths 等の紹介@PLDIr#3
Whole Program Paths 等の紹介@PLDIr#3
 
融合変換による最適化の理論的基盤と正当性 (2006-06-27)
融合変換による最適化の理論的基盤と正当性 (2006-06-27)融合変換による最適化の理論的基盤と正当性 (2006-06-27)
融合変換による最適化の理論的基盤と正当性 (2006-06-27)
 
融合変換による最適化の理論的基盤と正当性 (2006-06-20)
融合変換による最適化の理論的基盤と正当性 (2006-06-20)融合変換による最適化の理論的基盤と正当性 (2006-06-20)
融合変換による最適化の理論的基盤と正当性 (2006-06-20)
 
Ruby-GNOME2におけるGC問題
Ruby-GNOME2におけるGC問題Ruby-GNOME2におけるGC問題
Ruby-GNOME2におけるGC問題
 
LLW2004 その場でどう書く - Haskell
LLW2004 その場でどう書く - HaskellLLW2004 その場でどう書く - Haskell
LLW2004 その場でどう書く - Haskell
 

Recently uploaded

論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...Toru Tamaki
 
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案sugiuralab
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNetToru Tamaki
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものですiPride Co., Ltd.
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdftaisei2219
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Yuma Ohgami
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)Hiroki Ichikura
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A surveyToru Tamaki
 

Recently uploaded (8)

論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
 
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものです
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdf
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey
 

Relaxed Dependency Analysis

  • 1. Relaxed Dependency Analysis 〜Haskell 2009年末の集い〜 酒井 政裕
  • 2. ⾃⼰紹介 酒井 政裕 • Blog: ヒビルテ • Twitter: @masahiro_sakai • 2001年末ごろにHaskellに遭遇 • 好きな関数: unfoldr
  • 3. 背景: Haskellの型推論の流れ • 依存関係(の強連結成分)で定義をグループ化 • 末端のグループから順に型推論 • 例: 以下では b, c の型をまず推論し、その 結果を使って a の型を推論 –a=…b… a –b=…c… –c=…b… b c
  • 4. Relaxed Dependency Analysis • 依存関係の定義の変更 – Haskell98では、aがbを参照していれば、 aはbに依存していた – Haskell2010では、bに型宣⾔がある場合には、 aがbを参照していても、依存とはみなさない • 効果 – より多相的な型を推論出来るようになる – これまで型宣⾔が必要だったのが、不要にな ることがある
  • 5. 例: Haskell98の場合 • fとgは相互に依存してい f :: Eq a ⇒ a → Bool るので、同時に型推論 f x = (x == x) ∨ g True f g ∨ g “Yes” g y = (y ≤ y) ∨ f True • g が⼆通りの型で使われ ている – Bool → Bool – String → Bool • ⇒ 型エラー
  • 6. 例: Haskell2010の場合 • fには型宣⾔があるので、 f :: Eq a ⇒ a → Bool gはfには依存しない f x = (x == x) ∨ g True ∨ g “Yes” f g × g y = (y ≤ y) ∨ f True • gを先に型推論して、 g :: ∀a. Ord a ⇒ a → Bool • fの型推論では、gの型変数 aをBoolとStringに具体化
  • 7. 何が起こっているのか? • Haskellの基づいているHindley-Milnerのアルゴ リズムでは、ある定義グループの型推論の最後 の段階で型を多相的にする。 • なので、先に型推論が済んでいる部分は、型が 多相的な型になっているので、それを任意に具 体化出来る。 • ⼀⽅、型推論中の部分は、型が多相的になって いないので、複数の型で使うことが出来ない。