Skip to content

Instantly share code, notes, and snippets.

@int-index
Created July 3, 2017 01:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save int-index/fd5f1c041a7806d09f53f8e5275f7c7a to your computer and use it in GitHub Desktop.
Save int-index/fd5f1c041a7806d09f53f8e5275f7c7a to your computer and use it in GitHub Desktop.
Coherent Reader
{-# LANGUAGE RankNTypes, ScopedTypeVariables, FlexibleContexts #-}
import Control.Monad.Reader
import Data.Reflection
import Data.Tagged
import Data.Proxy
f :: Reader String Int
f = do
a <- ask
return $ length a
-- coherent ask
ask' :: forall s a. Reifies s a => Tagged s a
ask' = unproxy reflect
-- coherent runReader
runReader' :: (forall s. Reifies s a => Tagged s x) -> a -> x
runReader' tx a = reify a (proxy tx)
f' :: Reifies s String => Tagged s Int
f' = do
a <- ask'
return $ length a
x :: Int
x = runReader f "Hello"
x' :: Int
x' = runReader' f' "Hello"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment