Skip to content

Instantly share code, notes, and snippets.

@Icelandjack
Last active November 5, 2019 11:46
Show Gist options
  • Save Icelandjack/3ad9b3b13552a1913f5c720d84f1fd35 to your computer and use it in GitHub Desktop.
Save Icelandjack/3ad9b3b13552a1913f5c720d84f1fd35 to your computer and use it in GitHub Desktop.
Deriving via StateT s IO, (IO `Compose` State s) and (State s `Compose` IO)
-- https://stackoverflow.com/questions/49587122/type-variable-location-in-transformers
{-# Language DerivingVia #-}
import Control.Applicative
import Control.Monad.State
import Data.Functor.Compose
import Data.Functor.Identity
-- >> :instances StateT _ IO
-- instance Alternative (StateT _ IO)
-- instance Applicative (StateT _ IO)
-- instance Monad (StateT _ IO)
-- instance MonadPlus (StateT _ IO)
-- instance MonadFix (StateT _ IO)
-- instance MonadFail (StateT _ IO)
-- instance MonadIO (StateT _ IO)
-- instance Functor (StateT _ IO)
newtype One s a = One (s -> IO (a, s))
deriving (Functor, Applicative, Alternative, Monad, MonadPlus, MonadFix, MonadFail, MonadIO)
via StateT s IO
-- >> :instances IO `Compose` State _
-- instance Functor (Compose IO (State _ Identity))
-- instance Alternative (Compose IO (State _))
-- instance Applicative (Compose IO (State _))
newtype Two s a = Two (IO (s -> (a, s)))
deriving (Functor, Applicative, Alternative)
via IO `Compose` State s
-- >> :instances State _ `Compose` IO
-- instance Applicative (Compose (State _) IO)
-- instance Functor (Compose (State _) IO)
newtype Three s a = Three (s -> (IO a, s))
deriving (Functor, Applicative)
via State s `Compose` IO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment