Skip to content

Instantly share code, notes, and snippets.

@mankyKitty
Last active September 18, 2019 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mankyKitty/7d487fe884d5f832068397111ffd71f3 to your computer and use it in GitHub Desktop.
Save mankyKitty/7d487fe884d5f832068397111ffd71f3 to your computer and use it in GitHub Desktop.
weeeee
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