What should a “higher order Traversable” class look like?

前端 未结 1 1064
-上瘾入骨i
-上瘾入骨i 2021-01-19 01:01

In this answer I made up on the spot something which looks a bit like a \"higher order Traversable\": like Traversable but for functors from the ca

1条回答
  •  执笔经年
    2021-01-19 01:49

    In first order, we have sequence = traverse id.

    Here the first argument of htraverse has type forall x. f x -> a (g x), we can't have id, but we can try with an isomorphism instead. For f x to be isomorphic to a (g x), we can pick f ~ Compose a g.

    htraverse = hsequence . hmap (Compose . eta)
    
    hsequence :: Applicative a => t (Compose a g) -> a (t g)
    hsequence = htraverse getCompose
    

    0 讨论(0)
提交回复
热议问题