Skip to content

Instantly share code, notes, and snippets.

@acowley
Created February 17, 2015 01:21
Show Gist options
  • Save acowley/89b483e6b6d7203ab6db to your computer and use it in GitHub Desktop.
Save acowley/89b483e6b6d7203ab6db to your computer and use it in GitHub Desktop.
No Transformer Stack
{-# 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