Last active
September 18, 2019 06:03
-
-
Save mankyKitty/7d487fe884d5f832068397111ffd71f3 to your computer and use it in GitHub Desktop.
weeeee
This file contains hidden or 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
class MkTuple (xs :: [(a, Type)]) where | |
type AsTuple xs :: * | |
mkTuple :: NP P xs -> AsTuple xs | |
instance MkTuple '[] where | |
type AsTuple '[] = () | |
mkTuple _ = () | |
instance MkTuple xss => MkTuple (x ': xss) where | |
type AsTuple (x : xss) = (Snd x, AsTuple xss) | |
mkTuple (P x :* xss) = (x, mkTuple xss) | |
dismantle :: (IsRecord a xs , MkTuple xs) => a -> AsTuple xs | |
dismantle = mkTuple . toRecord | |
-- :D | |
(>*<) :: Divisible f => f a -> f b -> f (a,b) | |
(>*<) = divided | |
infixr 5 >*< | |
data Image = Image | |
{ _imageWidth :: Int | |
, _imageHeight :: Int | |
, _imageTitle :: Text | |
, _imageAnimated :: Bool | |
, _imageIDs :: [Int] | |
} | |
deriving (Show, Eq, GHC.Generic) | |
instance Generic Image | |
eImg :: Applicative f => E.ObjEncoder f Image | |
eImg = dismantle | |
>$< _toObj "Width" E.int | |
>*< _toObj "Height" E.int | |
>*< _toObj "Title" E.text | |
>*< _toObj "Animated" E.bool | |
>*< _toObj "IDs" (E.list E.int) | |
>*< conquer | |
where | |
_toObj k enc = E.objEncoder $ \x -> | |
E.onObj k x enc mempty |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment