Is there a class with the function `(m a -> n b) -> t m a -> t n b`
Asked Answered
L

1

6

Here's a class, I'm calling BlahMap:

class BlahMap t where
  blahMap :: (m a -> n b) -> t m a -> t n b

This is an instance of BlahMap:

instance BlahMap (ReaderT r) where
  blahMap f = ReaderT . fmap f . runReaderT

Is there an existing class in the Haskell ecosystem that does this? Or alternatively, can I just write a function blahMap with appropriate constraints with existing classes in say mtl or something similar? Or have I actually invented something new?

Ledbetter answered 13/10, 2022 at 3:11 Comment(0)
L
7

The function hoist from the class MFunctor, package mmorph is the answer to my own question.

Ledbetter answered 13/10, 2022 at 3:14 Comment(1)
To be completely correct, hoist has type (forall a. m a -> n a) -> t m b -> t n b, which is not exactly what you asked for in the OP. That being said, hoist is probably what you're looking for and is a very useful function to know, so I like this answer. Just worth noting that the types don't exactly line up.Indemnification

© 2022 - 2024 — McMap. All rights reserved.