@@ -6,15 +6,17 @@ import ProjectM36.Base
66import GHC.Generics
77import qualified Data.Text as T
88import qualified Data.Map as M
9−import Data.Typeable
9+--import Data.Typeable
10+--import Debug.Trace
1011
1112data TestT = TestC Int
12− deriving Generic
13+ deriving (Generic, Show)
1314
1415data Test2T x = Test2C x
15− deriving Generic
16+ deriving (Show, Generic)
1617
1718instance Atomable TestT
19+instance Atomable a => Atomable (Test2T a)
1820
1921class Atomable a where
2022 --type AtomT a
@@ -30,44 +32,63 @@ instance Atomable Int where
3032 toAtom i = IntAtom i
3133 toAtomType _ = IntAtomType
3234
35+instance Atomable Text where
36+ toAtom i = TextAtom i
37+ toAtomType _ = TextAtomType
38+
3339-- Generics
3440class AtomableG g where
3541 --type AtomTG g
3642 toAtomG :: g a -> Atom
37− toAtomTypeG :: g a -> AtomType
38−
39−class TypeVarMappableG g where
40− toTypeVarMap :: g a -> TypeVarMap
43+ toAtomTypeG :: g a -> AtomType --overall ConstructedAtomType
44+ toAtomTypesG :: g a -> [AtomType] --built from individual atom types
4145
46+{-
4247instance (AtomableG a, AtomableG b) => AtomableG (a :*: b) where
4348 --type AtomTG (a :*: b) = (AtomTG a, AtomTG b)
4449 toAtomG v = undefined
4550 toAtomTypeG v = undefined
46−
47−instance (AtomableG a, AtomableG b) => AtomableG (a :+: b) where
51+-}
52+-- Right | Left
53+ {-
54+instance (AtomableG (a p), AtomableG (b p)) => AtomableG ((a :+: b) p) where
4855 --type AtomTG (a :+: b) = (AtomTG a, AtomTG b)
4956 toAtomG v = undefined
5057 toAtomTypeG v = undefined
5158
59+-- Test Int Int
60+instance (Atomable (a p), Atomable (b p)) => AtomableG ((a :*: b) p) where
61+ toAtomG = undefined
62+ toAtomTypeG (x :*: y) = undefined
63+-}
64+
5265--data type metadata
53−instance (Datatype c, TypeVarMappableG a) => AtomableG (M1 D c a) where
66+instance (Datatype c, AtomableG a) => AtomableG (M1 D c a) where
5467 --type AtomTG (M1 D c a) = AtomTG a
5568 toAtomG = undefined
69+ toAtomTypesG = undefined
5670 toAtomTypeG (M1 v) = ConstructedAtomType (T.pack typeName) tvMap
5771 where
72+ aTypes = toAtomTypesG v
73+ a2z = map T.singleton ['a'..'z']
74+ tvMap = M.fromList (zip a2z aTypes)
5875 typeName = datatypeName (undefined :: M1 D c a x)
59− tvMap = toTypeVarMap v
60−
61−instance TypeVarMappableG (M1 C c a) where
76+
77+
78+instance (Constructor c, AtomableG a) => AtomableG (M1 C c a) where
6279 --M.Map TypeVarName AtomType
63− toTypeVarMap (M1 v) = M.empty
64−
65−{-
66−instance Atomable c => AtomableG (M1 S c (Rec0 f)) where
80+ --constructor name needed for Atom but not for atomType
81+ toAtomG (M1 _) = ConstructedAtom (T.pack constructorName) AnyAtomType []
82+ where
83+ constructorName = conName (undefined :: M1 C c a x)
84+ toAtomTypeG = undefined
85+ toAtomTypesG (M1 v) = toAtomTypesG v
86+
87+instance Atomable f => AtomableG (M1 S c (Rec0 f)) where
6788 toAtomG = undefined
68− toAtomTypeG (M1 v) = toAtomType v
69−
70−-}
89+ toAtomTypeG = undefined
90+ toAtomTypesG _ = [toAtomType (undefined :: f)]
91+
7192{-
7293--constructor metadata
7394instance AtomableG a => AtomableG (M1 C c a) where