[Haskell-cafe] Some questions on Atkey-style indexed monads

Tom Ellis tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk
Sun Dec 4 21:08:18 UTC 2022


On Sun, Dec 04, 2022 at 06:05:28PM +0100, Nicolas Trangez wrote:
> For some project, I'm considering (again) to use an indexed state
> monad, which are now somewhat ergonomic to use with QualifiedDo.
> 
> When looking into existing packages exposing relevant types/classes, I
> had some questions:
> 
> 1. These packages provide something like
> 
> ```
> class IxFunctor f where
>     imap :: (a -> b) -> f i j a -> f i j b
> 
> class IxFunctor f => IxApplicative f where
>     ...
> ```
> 
> Is this `IxFunctor` actually required/useful? It seems to me the
> implementation of `imap` for some `IxFunctor f` would be equal to
> `fmap` in the `Functor` implementation for `forall i j. f i j`. Hence,
> can `IxFunctor` be dropped in lieu of
> 
> ```
> class (forall i j. Functor (f i j)) => IxApplicative f where
>     ...
> ```

I suspect QualifiedConstraints didn't exist at the time that class was
introduced.  I agree in modern GHC-flavoured Haskell the quantified
constraint version is better.

Tom


More information about the Haskell-Cafe mailing list