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 methods20100529
tmiya
 

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

融合変換による最適化の理論的基盤と正当性 (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
 
LLW2004 その場でどう書く - Haskell
LLW2004 その場でどう書く - HaskellLLW2004 その場でどう書く - Haskell
LLW2004 その場でどう書く - 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 自己紹介(酒井)
 
自動定理証明の紹介
自動定理証明の紹介自動定理証明の紹介
自動定理証明の紹介
 
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

Recently uploaded (10)

Utilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native IntegrationsUtilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native Integrations
 
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
 
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
 
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
 
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
 
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。
 
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
 
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
 
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
 

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のアルゴ リズムでは、ある定義グループの型推論の最後 の段階で型を多相的にする。 • なので、先に型推論が済んでいる部分は、型が 多相的な型になっているので、それを任意に具 体化出来る。 • ⼀⽅、型推論中の部分は、型が多相的になって いないので、複数の型で使うことが出来ない。