Created
July 3, 2017 01:11
-
-
Save int-index/fd5f1c041a7806d09f53f8e5275f7c7a to your computer and use it in GitHub Desktop.
Coherent Reader
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 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