tagless-final

Two polymorphic classes in one function

99封情书 提交于 2020-05-29 07:03:31
问题 I have this code with State monads: import Control.Monad.State data ModelData = ModelData String data ClientData = ClientData String act :: String -> State ClientData a -> State ModelData a act _ action = do let (result, _) = runState action $ ClientData "" return result addServer :: String -> State ClientData () addServer _ = return () scenario1 :: State ModelData () scenario1 = do act "Alice" $ addServer "https://example.com" I am trying to generalise it with polymorphic type-classes

Two polymorphic classes in one function

走远了吗. 提交于 2020-05-29 07:03:17
问题 I have this code with State monads: import Control.Monad.State data ModelData = ModelData String data ClientData = ClientData String act :: String -> State ClientData a -> State ModelData a act _ action = do let (result, _) = runState action $ ClientData "" return result addServer :: String -> State ClientData () addServer _ = return () scenario1 :: State ModelData () scenario1 = do act "Alice" $ addServer "https://example.com" I am trying to generalise it with polymorphic type-classes

Two polymorphic classes in one function

谁说我不能喝 提交于 2020-05-29 07:02:13
问题 I have this code with State monads: import Control.Monad.State data ModelData = ModelData String data ClientData = ClientData String act :: String -> State ClientData a -> State ModelData a act _ action = do let (result, _) = runState action $ ClientData "" return result addServer :: String -> State ClientData () addServer _ = return () scenario1 :: State ModelData () scenario1 = do act "Alice" $ addServer "https://example.com" I am trying to generalise it with polymorphic type-classes

Interpreters for two polymorphic classes in one function

允我心安 提交于 2020-03-25 18:21:24
问题 I have this polymorphic code (see this question) with generic monads for model and client: import Control.Monad.Writer class Monad m => Model m where act :: Client c => String -> c a -> m a class Monad c => Client c where addServer :: String -> c () scenario1 :: forall c m. (Client c, Model m) => m () scenario1 = do act "Alice" $ addServer @c "https://example.com" and this is the pretty-print interpreter for the Client that explains the actions in the log via Writer monad: type Printer =

Interpreters for two polymorphic classes in one function

百般思念 提交于 2020-03-25 18:21:13
问题 I have this polymorphic code (see this question) with generic monads for model and client: import Control.Monad.Writer class Monad m => Model m where act :: Client c => String -> c a -> m a class Monad c => Client c where addServer :: String -> c () scenario1 :: forall c m. (Client c, Model m) => m () scenario1 = do act "Alice" $ addServer @c "https://example.com" and this is the pretty-print interpreter for the Client that explains the actions in the log via Writer monad: type Printer =