|
| 1 | +--- |
| 2 | +title: Haskell Symposium 2019 レポート |
| 3 | +subHeading: "" |
| 4 | +headingBackgroundImage: ../../img/background.png |
| 5 | +headingDivClass: post-heading |
| 6 | +author: Kazuki Okamoto |
| 7 | +postedBy: <a href="https://twitter.com/kakkun61">Kazuki Okamoto (@kakkun61)</a> |
| 8 | +date: October 1, 2019 |
| 9 | +tags: ICFP, Haskell Symposium |
| 10 | +--- |
| 11 | + |
| 12 | +[Haskell Symposium 2019](https://icfp19.sigplan.org/home/haskellsymp-2019)にIIJとして参加してきました。 |
| 13 | + |
| 14 | +聴講した発表についての概要をまとめましたので、どの論文を読んでみるか決めるなどの際にご活用ください。内容については私の聞きまちがい・読みまちがいなどあると思いますのでご了承ください。 |
| 15 | + |
| 16 | +# Haskell Symposiumとは |
| 17 | + |
| 18 | +[International Conference on Functional Programming](https://icfp19.sigplan.org/)(ICFP)に合わせて開催されるHaskellに関する国際会議です。Haskellに関する研究を発表したり、実践的な経験や将来の言語の開発について議論したり、その他の宣言的プログラミングを促進したりします。 |
| 19 | + |
| 20 | +# Bidirectional Type Class Instances |
| 21 | + |
| 22 | +- 著者:Koen Pauwels (KU Leuven), Georgios Karachalias (KU Leuven), Michiel Derhaeg (Guardsquare), Tom Schrijvers (KU Leuven) |
| 23 | +- 概要:<https://icfp19.sigplan.org/details/haskellsymp-2019-papers/8/Bidirectional-Type-Class-Instances> |
| 24 | +- 論文:<https://arxiv.org/abs/1906.12242> |
| 25 | + |
| 26 | +GADTと型クラスはそれぞれ便利だが混ぜると問題が起きる場合がある。 |
| 27 | + |
| 28 | +次のような`Term`があるとき、その`Show`インスタンスを考える。 |
| 29 | + |
| 30 | +```haskell |
| 31 | +data Term :: Type -> Type where |
| 32 | + Con :: a -> Term a |
| 33 | + Tup :: Term b -> Term c -> Term (b, c) |
| 34 | +``` |
| 35 | + |
| 36 | +次のように`Show`インスタンスを定義すると型エラーになる。 |
| 37 | + |
| 38 | +```haskell |
| 39 | +instance Show a => Show (Term a) where |
| 40 | + show (Con a) = show a |
| 41 | + show (Tup x y) = unwords ["(", show x, ",", show y, ")"] |
| 42 | +``` |
| 43 | + |
| 44 | +``` |
| 45 | +Could not deduce (Show b) arising from a use of `show' |
| 46 | +from the context (Show a) or from (a ~ (b, c)) |
| 47 | +``` |
| 48 | + |
| 49 | +これは`Show (b, c)`ならば`Show b`という関係がないために起こる。 |
| 50 | + |
| 51 | +一方タプルについての`Show`は、`Show a`かつ`Show b`ならば`Show (a, b)`という関係である。 |
| 52 | + |
| 53 | +```haskell |
| 54 | +instance (Show a, Show b) => Show (a, b) where |
| 55 | + … |
| 56 | +``` |
| 57 | + |
| 58 | +この「ならば」を両方向にすれば問題は解決できるのではないかというのが、この論文の主張である。 |
| 59 | + |
| 60 | +# Generic and Flexible Defaults for Verified, Law-Abiding Type-Class Instances |
| 61 | + |
| 62 | +- 著者:Ryan Scott (Indiana University), Ryan R. Newton (Indiana University) |
| 63 | +- 概要:<https://icfp19.sigplan.org/details/haskellsymp-2019-papers/3/Generic-and-Flexible-Defaults-for-Verified-Law-Abiding-Type-Class-Instances> |
| 64 | +- 論文:<https://ryanglscott.github.io/papers/verified-classes.pdf> |
| 65 | + |
| 66 | +型クラスの法則は依存型を使えば証明できるが、インスタンスごとに書くのはめんどうなので`Generics`で出来るようにしようという話である。 |
| 67 | + |
| 68 | +# Modular effects in Haskell through effect polymorphism and explicit dictionary applications - A new approach and the μVeriFast verifier as a case study |
| 69 | + |
| 70 | +- 著者:Dominique Devriese (Vrije Universiteit Brussel) |
| 71 | +- 概要・論文:<https://icfp19.sigplan.org/details/haskellsymp-2019-papers/1/Modular-effects-in-Haskell-through-effect-polymorphism-and-explicit-dictionary-applic> |
| 72 | + |
| 73 | +様々な種類の効果が複雑に絡み合うアプリケーションを整理するために、「効果を伴う処理を持った辞書」を明示的に渡す方式の提案である。 |
| 74 | + |
| 75 | +提案した方式によってVeriFastを再実装してみることで、実際に発生した問題と解決方法を解説している。 |
| 76 | + |
| 77 | +# Verifying Effectful Haskell Programs in Coq |
| 78 | + |
| 79 | +- 著者:Jan Christiansen (Flensburg University of Applied Sciences), Sandra Dylus (University of Kiel), Niels Bunkenburg (University of Kiel) |
| 80 | +- 概要:<https://icfp19.sigplan.org/details/haskellsymp-2019-papers/4/Verifying-Effectful-Haskell-Programs-in-Coq> |
| 81 | +- 論文:<https://dl.acm.org/citation.cfm?id=3342592> |
| 82 | + |
| 83 | +Coqによる、効果を伴うプログラムの証明に関する話。 |
| 84 | + |
| 85 | +効果について直接証明することはせず、Freeモナドを用いての証明を試みても、そのままCoqに翻訳すると停止性チェックによってエラーになってしまう。 |
| 86 | + |
| 87 | +そのために行った工夫に加え、具体例として、`trace`や(部分関数による)エラーなど、Haskellにおいて暗黙に発生する効果を考慮したモデル化について検討した。 |
| 88 | + |
| 89 | +# Solving Haskell equality constraints using Coq |
| 90 | + |
| 91 | +- 著者:Zubin Duggal |
| 92 | +- 概要・論文:<https://icfp19.sigplan.org/details/haskellsymp-2019-papers/15/Solving-Haskell-equality-constraints-using-Coq> |
| 93 | + |
| 94 | +data kindsやtype familiesといったGHC拡張によって厳格なデータ型を定義できるが、それに対する操作を定義するとGHCには解けない型レベルの等式が生成されることがある。 |
| 95 | + |
| 96 | +制約カインドの型に対する型クラスとして`Proven`を提供し、この制約がある箇所をGHC型検査プラグインが検出して対応するCoqコードのテンプレートを生成する。 |
| 97 | + |
| 98 | +そのCoqコードに証明がなければ警告を表示する。 |
| 99 | + |
| 100 | +```haskell |
| 101 | +type ProofName = Symbol |
| 102 | + |
| 103 | +class c => Proven (prf :: ProofName) (c :: Constraint) |
| 104 | + where {} |
| 105 | + |
| 106 | +applyProof :: forall prf c a. Proven prf c => (c => a) -> a |
| 107 | +applyProof x = x |
| 108 | + |
| 109 | +lemma3 = applyProof @"nonzero_pop" @(NNonZero (Popcount b) ~ True) Refl |
| 110 | +``` |
| 111 | + |
| 112 | +いくつか制約があるがHaskellの型をCoqに自動的に変換している。 |
| 113 | + |
| 114 | +# Formal Verification of Spacecraft Control Programs: An Experience Report |
| 115 | + |
| 116 | +- 著者:Andrey Mokhov (Newcastle University), Georgy Lukyanov (Newcastle University), Jakob Lechner (RUAG Space Austria GmbH) |
| 117 | +- 概要:<https://icfp19.sigplan.org/details/haskellsymp-2019-papers/5/Formal-Verification-of-Spacecraft-Control-Programs-An-Experience-Report> |
| 118 | +- 論文:<https://dl.acm.org/citation.cfm?id=3342593> |
| 119 | + |
| 120 | +REDFINという固定小数演算と整数演算のための処理系があるのだが、そのアセンブリーコードに対して形式検証をしたという報告である。 |
| 121 | + |
| 122 | +# G2Q: Haskell Constraint Solving |
| 123 | + |
| 124 | +- 著者:William T. Hallahan (Yale University), Anton Xue (Yale University), Ruzica Piskac (Yale University) |
| 125 | +- 概要:<https://icfp19.sigplan.org/details/haskellsymp-2019-papers/2/G2Q-Haskell-Constraint-Solving> |
| 126 | +- 論文:<https://dl.acm.org/citation.cfm?id=3342590> |
| 127 | + |
| 128 | +G2QはHaskellのソースにquasi quoteで埋め込むDSLである。 |
| 129 | + |
| 130 | +Haskellで書いた条件式をsymbolic executionして、SMT solverに渡す式に変換して、SMT solverに条件を満たす関数を導出させる。 |
| 131 | + |
| 132 | +# Making a Faster Curry with Extensional Types |
| 133 | + |
| 134 | +- 著者:Paul Downen (University of Oregon), Zachary Sullivan, Zena M. Ariola (University of Oregon), Simon Peyton Jones (Microsoft) |
| 135 | +- 概要:<https://icfp19.sigplan.org/details/haskellsymp-2019-papers/6/Making-a-Faster-Curry-with-Extensional-Types> |
| 136 | +- 論文:<https://ix.cs.uoregon.edu/~pdownen/publications/eta.pdf> |
| 137 | + |
| 138 | +パフォーマンスのためにη変換してほしいところを明示したいことがある。 |
| 139 | + |
| 140 | +例えば、次のような意味論上は等価な関数`f1`と`f2`があるとする。 |
| 141 | + |
| 142 | +```haskell |
| 143 | +f1 = \x -> let z = h x x in \y -> e y z |
| 144 | +f2 = \x -> \y -> let z = h x x in e y z |
| 145 | +``` |
| 146 | + |
| 147 | +実際は`f1`は引数`x`を取った後クロージャー生成のためにヒープ確保するのに対して、`f2`はアリティが2の関数と解釈されて中間のクロージャーが必要なくなる。 |
| 148 | + |
| 149 | +`~>`というアリティの情報を持った関数型を新たに導入して`->`の代わりに使えるようにする。 |
| 150 | + |
| 151 | +`TYPE (a :: RuntimeRep (FunRep 2))`というような新たなポリモーフィズムを導入する。ここでの`2`がアリティ。 |
| 152 | + |
| 153 | +`Int`に対して`Int#`があるように基本的にはパフォーマンスが必要なライブラリーなど内部的に使用する想定。 |
| 154 | + |
| 155 | +# Multi-Stage Programs in Context |
| 156 | + |
| 157 | +- 著者:Matthew Pickering (University of Bristol), Nicolas Wu (Imperial College London), Csongor Kiss (Imperial College London) |
| 158 | +- 概要:<https://icfp19.sigplan.org/details/haskellsymp-2019-papers/9/Multi-Stage-Programs-in-Context> |
| 159 | +- 論文:<https://dl.acm.org/citation.cfm?id=3342597> |
| 160 | + |
| 161 | +次のような準引用があったときに、組み合わせると元々あったはずの情報が欠落する場合がある。 |
| 162 | + |
| 163 | +```haskell |
| 164 | +qshow :: Code (Int -> String) |
| 165 | +qshow = [q| show |] |
| 166 | + |
| 167 | +qread :: Code (String -> Int) |
| 168 | +qread = [q| read |] |
| 169 | + |
| 170 | +trim :: Code (String -> String) |
| 171 | +trim = [q| $(qshow) . $(qread) |] |
| 172 | +``` |
| 173 | + |
| 174 | +`qshow`と`qread`にあった`Int`という情報が、組み合わせて`trim`とすると欠落してコンパイルエラーになってしまう。 |
| 175 | + |
| 176 | +spliceするときにHaskellソースコードの構文木ではなくCoreに対するものを出力すればそれは型が明示されているし問題がない。 |
| 177 | + |
| 178 | +しかも、splice後の型検査を省略できるのでコンパイルの高速化にも寄与する。 |
| 179 | + |
| 180 | +# Working with Source Plugins |
| 181 | + |
| 182 | +- 著者:Matthew Pickering (University of Bristol), Nicolas Wu (Imperial College London), Boldizsár Németh (Eötvös Loránd University) |
| 183 | +- 概要:<https://icfp19.sigplan.org/details/haskellsymp-2019-papers/11/Working-with-Source-Plugins> |
| 184 | +- 論文:<https://dl.acm.org/citation.cfm?id=3342599> |
| 185 | + |
| 186 | +souce pluginsのしくみや、書き方、実装時のテクニックの紹介である。 |
| 187 | + |
| 188 | +# STCLang: State Thread Composition as a Foundation for Monadic Dataflow Parallelism |
| 189 | + |
| 190 | +- 著者:Sebastian Ertel, Justus Adam (Technische Universität Dresden), Norman A. Rink (TU Dresden), Andrés Goens, Jeronimo Castrillon (TU Dresden) |
| 191 | +- 概要:<https://icfp19.sigplan.org/details/haskellsymp-2019-papers/12/STCLang-State-Thread-Composition-as-a-Foundation-for-Monadic-Dataflow-Parallelism> |
| 192 | +- 論文:<https://dl.acm.org/citation.cfm?id=3342600> |
| 193 | + |
| 194 | +同じ時刻のHIWの発表を聴講していたためこちらは聴講していません。 |
| 195 | + |
| 196 | +# Synthesizing Functional Reactive Programs |
| 197 | + |
| 198 | +- 著者:Bernd Finkbeiner, Felix Klein (Saarland University), Ruzica Piskac (Yale University, Mark Santolucito (Yale University) |
| 199 | +- 概要:<https://icfp19.sigplan.org/details/haskellsymp-2019-papers/13/Synthesizing-Functional-Reactive-Programs> |
| 200 | +- 論文:<https://dl.acm.org/citation.cfm?id=3342601> |
| 201 | + |
| 202 | +同じ時刻のHIWの発表を聴講していたためこちらは聴講していません。 |
| 203 | + |
| 204 | +# The essence of live coding: Change the program, keep the state! |
| 205 | + |
| 206 | +- 著者:Manuel Bärenz (sonnen eServices GmbH) |
| 207 | +- 概要・論文:<https://icfp19.sigplan.org/details/haskellsymp-2019-papers/14/The-essence-of-live-coding-Change-the-program-keep-the-state-> |
| 208 | + |
| 209 | +同じ時刻のHIWの発表を聴講していたためこちらは聴講していません。 |
| 210 | + |
| 211 | +# Monad Transformers and Modular Algebraic Effects: What Binds Them Together |
| 212 | + |
| 213 | +- 著者:Tom Schrijvers (KU Leuven), Maciej Piróg (University of Wrocław), Nicolas Wu (Imperial College London), Mauro Jaskelioff (CONICET) |
| 214 | +- 概要:<https://icfp19.sigplan.org/details/haskellsymp-2019-papers/7/Monad-Transformers-and-Modular-Algebraic-Effects-What-Binds-Them-Together> |
| 215 | +- 論文:<https://dl.acm.org/citation.cfm?id=3342595> |
| 216 | + |
| 217 | +モナドトランスフォーマーと代数的効果との対比である。 |
| 218 | + |
| 219 | +モナドトランスフォーマーから代数的効果への変換またその逆のときにどういう手法があって、それぞれを構成する要素がどう対応しているかを説明している。 |
| 220 | + |
| 221 | +モナドトランスフォーマーと代数的効果だとモナドトランスフォーマーの方が表現できるものが大きいのでモナドトランスフォーマーから代数的効果へはどんなものでも変換できるわけではない。 |
| 222 | + |
| 223 | +例えば`catch`や`local`は代数的効果にできない。 |
| 224 | + |
| 225 | +# Scoping Monadic Relational Database Queries |
| 226 | + |
| 227 | +- 著者:Anton Ekblad (Chalmers University of Technology) |
| 228 | +- 概要:<https://icfp19.sigplan.org/details/haskellsymp-2019-papers/10/Scoping-Monadic-Relational-Database-Queries> |
| 229 | +- 論文:<https://dl.acm.org/citation.cfm?id=3342598> |
| 230 | + |
| 231 | +モナドはHaskell界隈で非常に普及しているのでSQLに対するEDSLとしてモナドの構造を採用したい。 |
| 232 | + |
| 233 | +このときSQLの結合を表現すると、SQLとしてはスコープ外にもかかわらずEDSLとしてはスコープ内となって使える変数ができてしまう。 |
| 234 | + |
| 235 | +これをEDSLとしてもエラーとしたい。 |
| 236 | + |
| 237 | +例えば、次のような例で実行時エラーとなってしまう。ここで`a0`は`tableA`の列とする。 |
| 238 | + |
| 239 | +```SQL |
| 240 | +SELECT a0, b0 |
| 241 | +FROM |
| 242 | + tableA |
| 243 | + LEFT JOIN |
| 244 | + (SELECT b0 FROM tableB WHERE a0 == b1) |
| 245 | + ON tableA.a2 == tableb.b2 |
| 246 | +``` |
| 247 | + |
| 248 | +`SELECT b0 FROM tableB WHERE a0 == b1`の部分でスコープ外の`a0`を参照しているためエラーとなる。 |
| 249 | + |
| 250 | +単純なモナドEDSLだと次のようになりコンパイルが通る。 |
| 251 | + |
| 252 | +```haskell |
| 253 | +do |
| 254 | + a0 :*: a1 :*: a2 <- from table0 |
| 255 | + leftJoin $ do |
| 256 | + b0 :*: b1 :*: b2 <- from table1 |
| 257 | + ristrict $ a0 .== b1 |
| 258 | + on $ a2 .== b2 |
| 259 | +``` |
| 260 | + |
| 261 | +`ristrict $ a0 .== b1`の部分において`a0`はHaskellとしてはスコープ内にある。 |
| 262 | + |
| 263 | +この問題を次のような型レベル関数を駆使することでEDSLにおいてもコンパイル時エラーとすることができた。 |
| 264 | + |
| 265 | +```haskell |
| 266 | +type family Cols a |
| 267 | +type family Outer a |
| 268 | +type family UnAggr a |
| 269 | +type family FromRow a |
| 270 | +``` |
0 commit comments