
On 10/17/2017 01:13 AM, Albert Y. C. Lai wrote:
What is an example of how I would usually use withGADTDict?
The use case is accessing the dictionary in the context of a natural transformation, during a free applicative traversal [1]. I.e. given:
runAp_ :: Monoid m => (forall a. f a -> m) -> Ap f b -> m
..the 'GADT' type being the first argument for the 'Ap' type:
data GADT a where G1 :: HasDict a => a -> GADT a -- ...
..and the extraction function:
transform ∷ HasDict a => GADT a -> Result -- where 'Result' has a Monoid instance
..there needs to be a way to call 'transform' inside the natural transformation, the first argument of 'runAp_', which 'withGADTDict' neatly fits:
runAp_ (withGADTDict transform) someFreeAp
-- 1. https://hackage.haskell.org/package/free-4.12.4/docs/Control-Applicative-Fre... -- с уважениeм / respectfully, Kosyrev Serge PGP Key ID: 3F62F118E38BED6D -- “Most deadly errors arise from obsolete assumptions.” -- Frank Herbert, Children of Dune