Skip to content

Instantly share code, notes, and snippets.

@etorreborre
Created October 9, 2021 09:10
Show Gist options
  • Save etorreborre/acbc7059a266db44911f0388f2764ade to your computer and use it in GitHub Desktop.
Save etorreborre/acbc7059a266db44911f0388f2764ade to your computer and use it in GitHub Desktop.
Deriving FFunctor?
{-
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