From 9a113fe48b8837111599e1bc430cc3bc03c40754 Mon Sep 17 00:00:00 2001 From: Erik Post Date: Wed, 21 Aug 2019 19:57:22 +0200 Subject: [PATCH] Move assembleGens from Instance into Collage. #148 --- src/Language/CQL/Collage.hs | 15 +++++++++++++++ src/Language/CQL/Instance.hs | 14 +------------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/Language/CQL/Collage.hs b/src/Language/CQL/Collage.hs index 577201a..e530498 100644 --- a/src/Language/CQL/Collage.hs +++ b/src/Language/CQL/Collage.hs @@ -33,6 +33,7 @@ along with this program. If not, see . {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE StandaloneDeriving #-} +{-# LANGUAGE TupleSections #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE TypeSynonymInstances #-} {-# LANGUAGE UndecidableInstances #-} @@ -101,6 +102,20 @@ attsFrom sch en' = f $ Map.assocs $ catts sch where f [] = [] f ((fk,(en1,t)):l) = if en1 == en' then (fk,t) : (f l) else f l +type Carrier en fk gen = Term Void Void Void en fk Void gen Void + +assembleGens + :: (MultiTyMap '[Show, Ord, NFData] '[var, ty, sym, en, fk, att, gen, sk]) + => Collage var ty sym en fk att gen sk + -> [Carrier en fk gen] + -> Map en (Set (Carrier en fk gen)) +assembleGens col [] = Map.fromList $ fmap (, Set.empty) $ Set.toList $ cens col +assembleGens col (e:tl) = Map.insert t (Set.insert e s) m + where + m = assembleGens col tl + t = typeOf col e + s = m ! t + -- | Gets the type of a term that is already known to be well-typed. typeOf :: (MultiTyMap '[Show, Ord, NFData] '[var, ty, sym, en, fk, att, gen, sk]) diff --git a/src/Language/CQL/Instance.hs b/src/Language/CQL/Instance.hs index 3d1296a..4a4be35 100644 --- a/src/Language/CQL/Instance.hs +++ b/src/Language/CQL/Instance.hs @@ -49,8 +49,8 @@ import Data.Set (Set) import qualified Data.Set as Set import Data.Typeable hiding (typeOf) import Data.Void -import Language.CQL.Collage (Collage(..), attsFrom, fksFrom, typeOf, typeOfCol) import Language.CQL.Common (elem', intercalate, fromListAccum, mapl, section, sepTup, toMapSafely, Deps(..), Err, Kind(INSTANCE), MultiTyMap, TyMap, type (+)) +import Language.CQL.Collage (Collage(..), assembleGens, attsFrom, fksFrom, typeOf, typeOfCol) import Language.CQL.Mapping as Mapping import Language.CQL.Options import Language.CQL.Prover @@ -422,18 +422,6 @@ deriving instance TyMap Ord '[en, fk, att, gen, sk] => Ord (TalgGen en fk att ge deriving instance TyMap Eq '[fk, att, gen, sk] => Eq (TalgGen en fk att gen sk) -assembleGens - :: (MultiTyMap '[Show, Ord, NFData] '[var, ty, sym, en, fk, att, gen, sk]) - => Collage var ty sym en fk att gen sk - -> [Carrier en fk gen] - -> Map en (Set (Carrier en fk gen)) -assembleGens col [] = Map.fromList $ Prelude.map (, Set.empty) $ Set.toList $ cens col -assembleGens col (e:tl) = Map.insert t (Set.insert e s) m - where - m = assembleGens col tl - t = typeOf col e - s = m ! t - close :: (MultiTyMap '[Show, Ord, NFData] '[var, ty, sym, en, fk, att, gen, sk]) => Collage var ty sym en fk att gen sk