Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-# LANGUAGE TypeFamilies, DataKinds, GADTs, RankNTypes, UndecidableInstances #-}
  2.  
  3. module DatascriptExample () where
  4.  
  5. import Data.Proxy (Proxy(..))
  6.  
  7. type Id = Int
  8.  
  9. data Attribute = StringAttribute | IntAttribute
  10. data Cardinality = One | Many
  11.  
  12. type family AttributeType (attr :: Attribute)
  13. type instance AttributeType StringAttribute = String
  14. type instance AttributeType IntAttribute = Int
  15.  
  16. type family CardinalityType (card :: Cardinality) r
  17. type instance CardinalityType One r = r
  18. type instance CardinalityType Many r = [r]
  19.  
  20. type family ValueType (attr :: Attribute) (card :: Cardinality)
  21. type instance ValueType attr card = CardinalityType card (AttributeType attr)
  22.  
  23. data DAtom where
  24.   Entry :: forall (attr :: Attribute) (card :: Cardinality) . Id -> Proxy attr -> Proxy card -> ValueType attr card -> DAtom
  25.  
  26. example1 :: DAtom
  27. example1 = Entry 0 (Proxy :: Proxy StringAttribute) (Proxy :: Proxy Many) ["adf", "asdf"]
  28.  
  29. example2 :: DAtom
  30. example2 = Entry 0 (Proxy :: Proxy IntAttribute) (Proxy :: Proxy One) 10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement