Created
July 3, 2014 21:35
-
-
Save edwardgeorge/7e49adcb0f9e38ee2dd7 to your computer and use it in GitHub Desktop.
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 OverloadedStrings #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
module ReflectBark where | |
import Control.Applicative | |
import Data.Aeson | |
import Data.Proxy | |
import Data.Reflection | |
data Bark = Bark | Woof | Yelp | Yap deriving Show | |
newtype B s = B { getDog :: String } | |
instance Reifies s Bark => FromJSON (B s) where | |
parseJSON _ = B <$> (pure . show $ reflect (Proxy :: Proxy s)) | |
testdog :: Bark -> Maybe String | |
testdog s = reify s $ \r -> fmap (getDog . isProxyFor r) $ decode "{}" | |
where isProxyFor :: Proxy s -> f s -> f s | |
isProxyFor = flip const |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment