Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# LANGUAGE TypeFamilies, DataKinds, GADTs, RankNTypes, UndecidableInstances #-}
- module DatascriptExample () where
- import Data.Proxy (Proxy(..))
- type Id = Int
- data Attribute = StringAttribute | IntAttribute
- data Cardinality = One | Many
- type family AttributeType (attr :: Attribute)
- type instance AttributeType StringAttribute = String
- type instance AttributeType IntAttribute = Int
- type family CardinalityType (card :: Cardinality) r
- type instance CardinalityType One r = r
- type instance CardinalityType Many r = [r]
- type family ValueType (attr :: Attribute) (card :: Cardinality)
- type instance ValueType attr card = CardinalityType card (AttributeType attr)
- data DAtom where
- Entry :: forall (attr :: Attribute) (card :: Cardinality) . Id -> Proxy attr -> Proxy card -> ValueType attr card -> DAtom
- example1 :: DAtom
- example1 = Entry 0 (Proxy :: Proxy StringAttribute) (Proxy :: Proxy Many) ["adf", "asdf"]
- example2 :: DAtom
- example2 = Entry 0 (Proxy :: Proxy IntAttribute) (Proxy :: Proxy One) 10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement