generated at
Representable型クラス
Haskellでの表現可能関手の実装



hsの関連module, package
似たようなのがいくつかあるmrsekut
Data.Functor.Rep moduleで定義されてる
Naperian
naperian
Data.Functor.Representableもあるが古い
一応pursにもある ref


定義
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 を定義しても同じ
Data.Functor.Repでの定義では、以下の2つの型クラスを継承している
index , tabulate , positions の意味




何が嬉しい #??
あるいはどういう気持ち、動機でこれのinstanceにすることが想起される?
この辺は具体的なinstanceの使用例を見るのが良さそうmrsekut
e.g. Stream a は、 (Integer -> a) と自然同型になる
つまり、 Stream a の全要素と一対一対応するような関数 (Integer -> a) が存在することがわかる


Representableのインスタンス
(->) r
Identity
Diag
対角関手
Vector n a
Stream a
(Integer -> a) と自然同型になる
Product
Compose
後半




表現不可能なものの例
Either
Maybe
List
のような値が空のケースがあるもの

双対
たぶんFunctorに対するContravariant型クラスと同じ


Lensにもあるのか



参考
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
chrome-extension://oemmndcbldboiebfnladdacbdfmadadm/https://personal.cis.strath.ac.uk/conor.mcbride/so-pigworker.pdf