on master help sign in
fix broken instances of Atomable [a]

resolves #241

commitaa29193aa714e134d801bb529b96d614dd59356c authorAgentM <agentm@themactionfaction.com> dateSat 22 Jun 2019, 19:00 (7 years ago) parent46098e8
2 files changed+10−4
src/lib/ProjectM36/Atomable.hs+2−2 test/Relation/Atomable.hs+8−2
src/lib/ProjectM36/Atomable.hs+2−2
@@ -148,10 +148,10 @@ instance (Atomable a, Atomable b) => Atomable (Either a b) where
148148--convert to ADT list
149149instance Atomable a => Atomable [a] where
150150 toAtom [] = ConstructedAtom "Empty" (listAtomType (toAtomType (Proxy :: Proxy a))) []
151− toAtom (x:xs) = ConstructedAtom "Cons" (listAtomType (toAtomType (Proxy :: Proxy a))) (map toAtom (x:xs))
151+ toAtom (x:xs) = ConstructedAtom "Cons" (listAtomType (toAtomType (Proxy :: Proxy a))) (toAtom x: [toAtom xs])
152152
153153 fromAtom (ConstructedAtom "Empty" _ _) = []
154− fromAtom (ConstructedAtom "Cons" _ (x:xs)) = fromAtom x:map fromAtom xs
154+ fromAtom (ConstructedAtom "Cons" _ (x:y:[])) = fromAtom x:fromAtom y
155155 fromAtom _ = error "improper fromAtom [a]"
156156
157157 toAtomType _ = ConstructedAtomType "List" (M.singleton "a" (toAtomType (Proxy :: Proxy a)))
test/Relation/Atomable.hs+8−2
@@ -1,5 +1,5 @@
11--Test Atomable typeclass which allows users to use existing Haskell datatypes to marshal them to and from the database as ConstructedAtoms.
2−{-# LANGUAGE DeriveGeneric, DeriveAnyClass, OverloadedStrings #-}
2+{-# LANGUAGE DeriveGeneric, DeriveAnyClass, OverloadedStrings, TypeApplications #-}
33import Test.HUnit
44import ProjectM36.Client
55import Data.Binary
@@ -75,7 +75,7 @@ main = do
7575 if errors tcounts + failures tcounts > 0 then exitFailure else exitSuccess
7676
7777testList :: Test
78−testList = TestList [testHaskell2DB, testADT1, testADT2, testADT3, testADT4, testADT5, testBasicMarshaling, testListInstance, testNonEmptyInstance, testADT6Maybe, testADT7Either, testNonPrimitiveValues, testRecordType, testManyFields]
78+testList = TestList [testHaskell2DB, testADT1, testADT2, testADT3, testADT4, testADT5, testBasicMarshaling, testSimpleList, testListInstance, testNonEmptyInstance, testADT6Maybe, testADT7Either, testNonPrimitiveValues, testRecordType, testManyFields]
7979
8080-- test some basic data types like int, day, etc.
8181testBasicMarshaling :: Test
@@ -160,6 +160,12 @@ testListInstance = TestCase $ do
160160 let example = TestListC [3,4,5]
161161 assertEqual "List instance" example (fromAtom (toAtom example))
162162
163+testSimpleList :: Test
164+testSimpleList = TestCase $ do
165+ let example = toAtom @[Integer] [1,2,3]
166+ expected = ConstructedAtom "Cons" (ConstructedAtomType "List" (M.fromList [("a",IntegerAtomType)])) [IntegerAtom 1,ConstructedAtom "Cons" (ConstructedAtomType "List" (M.fromList [("a",IntegerAtomType)])) [IntegerAtom 2,ConstructedAtom "Cons" (ConstructedAtomType "List" (M.fromList [("a",IntegerAtomType)])) [IntegerAtom 3,ConstructedAtom "Empty" (ConstructedAtomType "List" (M.fromList [("a",IntegerAtomType)])) []]]]
167+ assertEqual "simple list" expected example
168+
163169testNonEmptyInstance :: Test
164170testNonEmptyInstance = TestCase $ do
165171 let example = TestNonEmptyC [3,4,5]