[Haskell-cafe] Exposing a GADT-provided dictionary

Kosyrev Serge serge.kosyrev at iohk.io
Tue Oct 17 12:56:05 UTC 2017


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-Free.html#v:runAp_
-- 
с уважениeм / respectfully,
Kosyrev Serge

PGP Key ID: 3F62F118E38BED6D
--
“Most deadly errors arise from obsolete assumptions.”
  -- Frank Herbert, Children of Dune


More information about the Haskell-Cafe mailing list