Skip to content

Instantly share code, notes, and snippets.

@scan
Forked from LeviSchuck/KV.hs
Last active December 20, 2015 07:49
Show Gist options
  • Save scan/6096533 to your computer and use it in GitHub Desktop.
Save scan/6096533 to your computer and use it in GitHub Desktop.
{-# LANGUAGE RecordWildCards, MultiParamTypeClasses, FlexibleInstances #-}
class KVEntity a b where
kvIdentity :: a -> KVIdentifier
kvProperties :: a -> Value
kvLastModified :: a -> UTCTime
kvClass :: a -> KVClass
kvRelations :: a -> [KVLink]
kvCachedRels :: a -> [b]
kvProperties _ = emptyObject
kvCachedRels _ = []
kvRelations _ = []
data KVFullEntity a = KVFullEntity
{ kvFullClass :: KVClass
, kvFullProperties :: Value
, kvFullIdentity :: KVIdentifier
, kvFullLastModified :: UTCTime
, kvFullRelations :: [KVLink]
, kvFullCachedRels :: [a]
}
instance (KVEntity a a) => KVEntity (KVFullEntity a) a where
kvIdentity KVFullEntity{..} = kvFullIdentity
kvProperties KVFullEntity{..} = kvFullProperties
kvLastModified KVFullEntity{..} = kvFullLastModified
kvClass KVFullEntity{..} = kvFullClass
kvRelations KVFullEntity{..} = kvFullRelations
kvCachedRels KVFullEntity{..} = kvFullCachedRels
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment