Skip to content

Instantly share code, notes, and snippets.

@edwardgeorge
Created July 3, 2014 21:35
Show Gist options
  • Save edwardgeorge/7e49adcb0f9e38ee2dd7 to your computer and use it in GitHub Desktop.
Save edwardgeorge/7e49adcb0f9e38ee2dd7 to your computer and use it in GitHub Desktop.
{-# 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