Representable型クラス
Haskellでの表現可能関手の実装
hsの関連module, package
似たようなのがいくつかあるmrsekut.icon
Data.Functor.Rep moduleで定義されてる
hackage
github
Naperian
hackage
naperian
hackage
Data.Functor.Representableもあるが古い
一応pursにもある ref
定義
code:hs
class Functor f => Representable f where
type Rep f :: *
index :: f a -> Rep f -> a
tabulate :: (Rep f -> a) -> f a
type Rep fの箇所はAssociated Type Family
tabulateの代わりにpositionsを定義しても同じ
Representable型クラスのtabulateとpositionsの同じさは米田の補題に裏付けられる
Data.Functor.Repでの定義では、以下の2つの型クラスを継承している
Indexable型クラス
Distributive型クラス
index, tabulate, positionsの意味
ref indexとtabulateとpositionsの意味
何が嬉しい #??
あるいはどういう気持ち、動機でこれのinstanceにすることが想起される?
この辺は具体的なinstanceの使用例を見るのが良さそうmrsekut.icon
e.g. Stream aは、(Integer -> a)と自然同型になる
つまり、Stream aの全要素と一対一対応するような関数(Integer -> a)が存在することがわかる
Representableのインスタンス
(->) r
Representableのinstance例: (->) r
Identity
Diag
対角関手
Vector n a
Representableのinstance例: Vector
Stream a
(Integer -> a)と自然同型になる
Representableのinstance例: Stream a
Product
Compose
https://stackoverflow.com/a/54266043
後半
https://qiita.com/lotz/items/5a1a05c0dae1133a5f44#表現可能関手のインスタンス
表現不可能なものの例
Either
Maybe
List
のような値が空のケースがあるもの
表現不可能な関手の例: List
双対
Corepresentable型クラス
https://hackage.haskell.org/package/adjunctions-4.4/docs/Data-Functor-Contravariant-Rep.html
たぶんFunctorに対するContravariant型クラスと同じ
#??
Lensにもあるのか
https://hackage.haskell.org/package/lens-3.6/docs/Control-Lens-Representable.html
Naperian Functor
参考
テンソルを実装するのに表現可能関手がとても便利な件 - Qiita
chrome-extension://oemmndcbldboiebfnladdacbdfmadadm/https://nickhu.co.uk/Acc-nap.pdf
chrome-extension://oemmndcbldboiebfnladdacbdfmadadm/https://www.cs.ox.ac.uk/people/jeremy.gibbons/publications/aplicative.pdf
https://gist.github.com/ChrisPenner/291038ae1343333fb41523b41181a9d4
https://blog.cofree.coffee/2020-10-17-bounded-space-automata/
https://stackoverflow.com/questions/46489376/which-haskell-functors-are-equivalent-to-the-reader-functor
http://blog.sigfpe.com/2009/11/memoizing-polymorphic-functions-with.html
http://comonad.com/reader/2013/representing-applicatives/
https://bitterharvest.hatenablog.com/entry/2018/05/26/105847
https://chrispenner.ca/posts/representable-discrimination
http://conal.net/blog/posts/memoizing-polymorphic-functions-via-unmemoization
chrome-extension://oemmndcbldboiebfnladdacbdfmadadm/https://personal.cis.strath.ac.uk/conor.mcbride/so-pigworker.pdf
https://www.reddit.com/r/haskell/duplicates/3f131q/representable_functors_from_bartosz_milewskis/
https://chrispenner.ca/posts/adjunction-battleship
https://www.reddit.com/r/haskell/comments/6vdbd0/adjunction_vs_representable/
https://eed3si9n.com/herding-cats/ja/Const.html