Created
February 17, 2015 01:21
-
-
Save acowley/89b483e6b6d7203ab6db to your computer and use it in GitHub Desktop.
No Transformer Stack
This file contains 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
{-# LANGUAGE DataKinds, FlexibleContexts, TypeOperators #-} | |
import Control.Monad.State | |
import Data.Vinyl | |
type OuterData = '("Outer", String) | |
type InnerData = '("Inner", String) | |
outerData :: SField OuterData | |
outerData = SField | |
innerData :: SField InnerData | |
innerData = SField | |
getOuterName :: (Functor m, MonadState (FieldRec s) m, OuterData ∈ s) | |
=> m String | |
getOuterName = fmap (getField . rget (SField::SField OuterData)) get | |
getInnerName :: (Functor m, MonadState (FieldRec s) m, InnerData ∈ s) | |
=> m String | |
getInnerName = fmap (getField . rget (SField::SField InnerData)) get | |
main :: IO () | |
main = flip evalStateT (innerData =: "inny" <+> outerData =: "outy") $ do | |
getInnerName >>= liftIO . putStrLn | |
getOuterName >>= liftIO . putStrLn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment