Created
October 9, 2021 09:10
-
-
Save etorreborre/acbc7059a266db44911f0388f2764ade to your computer and use it in GitHub Desktop.
Deriving FFunctor?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- | |
It would be nice to be able to derive a `FFunctor` instance for some data types as | |
shown below | |
-} | |
class FFunctor f where | |
ffmap :: (forall a. m a -> n a) -> f m -> f n | |
-- can we define a default ffmap which would work when m :: Type -> Type? | |
-- default ffmap | |
-- Application | |
data UserRepository (m :: Type -> Type) = UserRepository { | |
saveUser :: User -> m (), | |
findUser :: m User | |
} | |
-- what kind of deriving clause do we need here? | |
-- deriving Something | |
userRepositoryWithConfig :: UserRepository (ReaderT Int IO) | |
userRepositoryWithConfig = UserRepository { | |
saveUser = const (pure ()), | |
findUser = pure User | |
} | |
userRepository :: UserRepository IO | |
userRepository = ffmap (runReaderT 1) userRepositoryWithConfig |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment