Representable型クラス
hsの関連module, package
似たようなのがいくつかある

Naperian
naperian
定義
hsclass Functor f => Representable f where
type Rep f :: *
index :: f a -> Rep f -> a
tabulate :: (Rep f -> a) -> f a
tabulate
の代わりに positions
を定義しても同じ
index
, tabulate
, positions
の意味
あるいはどういう気持ち、動機でこれのinstanceにすることが想起される?
この辺は具体的なinstanceの使用例を見るのが良さそう

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
のような値が空のケースがあるもの
双対
Lensにもあるのか
参考