Skip to content

Instantly share code, notes, and snippets.

@supki
Created September 9, 2014 21:04
Show Gist options
  • Save supki/fa792f87d769d739650f to your computer and use it in GitHub Desktop.
Save supki/fa792f87d769d739650f to your computer and use it in GitHub Desktop.
EBLO
newtype FromJSON_ a = FromJSON_ { _parseJSON :: Value -> Parser a }
newtype T a s = T { unT :: a }
instance Reifies s (FromJSON_ a) => FromJSON (T a s) where
parseJSON = fmap T . _parseJSON (reflect (Proxy :: Proxy s))
parseJson :: forall a. (Value -> Parser a) -> ByteString -> Maybe a
parseJson f b = reify (FromJSON_ f) (\(_ :: Proxy s) -> fmap unT ((decode :: ByteString -> Maybe (T a s)) b))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment