generated at
Functional Dependencies
ここの説明がわかりやすい
FunctionalDependenciesの方も読まないと一般化できないmrsekut

関連論文


2つ以上の型変数を取る型クラスの定義に対して、
引数同士の関数関係を明示する

これを
purs(hs)
class Stream stream element where uncons :: stream -> Maybe { head :: element, tail :: stream }
こう書く
purs(hs)
class Stream stream element | stream -> element where uncons :: stream -> Maybe { head :: element, tail :: stream }
stream 型決まれば、 element 型が一意に決まる」ということを明示できる
なるほどmrsekut
つまり、この制限を加えると他の Stream String なんか の定義はできないということかmrsekut
試してみるmrsekut


purs(hs)
class Stream stream element | stream -> element where uncons :: stream -> Maybe { head :: element, tail :: stream } instance streamArray :: Stream (Array a) a where uncons = Array.uncons instance streamString :: Stream String String.CodePoint where uncons = String.uncons instance streamString :: Stream String Int where -- error!! uncons xs = Just { head: 1, tail: xs } instance streamString :: Stream Int String.CodePoint where -- error!! uncons xs = Just { head: String.codePointFromChar 'c', tail: xs }
確かにエラーになったmrsekut
下に書いたほうがエラーになる
コドメインが被っていてもエラーになる
Stream String なんか Stream なんか CodePoint もエラー
全単射じゃないといけないのかmrsekut


purs(hs)
class Union (left :: # Type) (right :: # Type) (union :: # Type) | left right -> union, right union -> left, union left -> right
3つの型引数を取っている
その中の任意の2つの型が決まれば、残りの一つも決まる、ということを言っっている

purs(hs)
class Cons (label :: Symbol) (a :: k) (tail :: Row k) (row :: Row k) | label a tail -> row, label row -> a tail
4つの型引数を取っている
label, a, tail と、 label, row の組み合わせに関しては、これが決まれば残りも一意に決まる、ということを言っている




psのRow型の型クラスにもやたら出てくるmrsekut



ここでみた