@@ -4,7 +4,6 @@ module ProjectM36.Atomable where
44--http://stackoverflow.com/questions/13448361/type-families-with-ghc-generics-or-data-data
55--instances to marshal Haskell ADTs to ConstructedAtoms and back
66import ProjectM36.Base
7−import ProjectM36.DataTypes.Primitive
87import ProjectM36.DataTypes.List
98import ProjectM36.DataTypes.NonEmptyList
109import ProjectM36.DataTypes.Maybe
@@ -12,13 +11,13 @@ import ProjectM36.DataTypes.Either
1211import GHC.Generics
1312import qualified Data.Map as M
1413import qualified Data.Text as T
14+import qualified Data.Vector as V
1515import Control.DeepSeq (NFData)
1616import Data.Binary
1717import Control.Applicative
1818import Data.Time.Calendar
1919import Data.ByteString (ByteString)
2020import Data.Time.Clock
21−import Data.Maybe
2221import Data.Proxy
2322import qualified Data.List.NonEmpty as NE
2423
@@ -242,10 +241,25 @@ instance (Atomable a) => AtomableG (K1 c a) where
242241 getConstructorsG = undefined
243242 getConstructorArgsG (K1 _) = [DataConstructorDefTypeConstructorArg tCons]
244243 where
245− tCons = PrimitiveTypeConstructor primitiveATypeName primitiveAType
246− primitiveAType = toAtomType (Proxy :: Proxy a)
247− primitiveATypeName = fromMaybe (error ("primitive type missing: " ++ show primitiveAType)) (foldr (\(PrimitiveTypeConstructorDef name typ, _) acc -> if typ == primitiveAType then Just name else acc) Nothing primitiveTypeConstructorMapping)
248−
244+ tCons = typeToTypeConstructor $ toAtomType (Proxy :: Proxy a)
245+
246+typeToTypeConstructor :: AtomType -> TypeConstructor
247+typeToTypeConstructor x@(IntAtomType) = PrimitiveTypeConstructor "Int" x
248+typeToTypeConstructor x@(IntegerAtomType) = PrimitiveTypeConstructor "Integer" x
249+typeToTypeConstructor x@(DoubleAtomType) = PrimitiveTypeConstructor "Double" x
250+typeToTypeConstructor x@(TextAtomType) = PrimitiveTypeConstructor "Text" x
251+typeToTypeConstructor x@(DayAtomType) = PrimitiveTypeConstructor "Day" x
252+typeToTypeConstructor x@(DateTimeAtomType) = PrimitiveTypeConstructor "DateTime" x
253+typeToTypeConstructor x@(ByteStringAtomType) = PrimitiveTypeConstructor "ByteString" x
254+typeToTypeConstructor x@(BoolAtomType) = PrimitiveTypeConstructor "Bool" x
255+typeToTypeConstructor (RelationAtomType attrs)
256+ = RelationAtomTypeConstructor $ map attrToAttrExpr $ V.toList attrs
257+ where
258+ attrToAttrExpr (Attribute n t) = AttributeAndTypeNameExpr n (typeToTypeConstructor t) ()
259+typeToTypeConstructor (ConstructedAtomType tcName tvMap)
260+ = ADTypeConstructor tcName $ map typeToTypeConstructor (M.elems tvMap)
261+typeToTypeConstructor (TypeVariableType tvName) = TypeVariable tvName
262+
249263instance AtomableG U1 where
250264 toAtomG = undefined
251265 fromAtomG _ _ = pure U1