Skip to content

Commit

Permalink
Remove duplicate simplifyAlg and rename to A.simplify. #148
Browse files Browse the repository at this point in the history
  • Loading branch information
epost committed Aug 22, 2019
1 parent 8e3517b commit b7712e6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 20 deletions.
19 changes: 2 additions & 17 deletions src/Language/CQL/Instance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import Data.Void
import Language.CQL.Collage (Collage(..), assembleGens, attsFrom, fksFrom, typeOf)
import Language.CQL.Common (elem', fromListAccum, section, toMapSafely, Deps(..), Err, Kind(INSTANCE), MultiTyMap, TyMap, type (+))
import Language.CQL.Instance.Algebra (Algebra(..), aAtt, down1, evalSchTerm, evalSchTerm', nf, nf'', repr'')
import qualified Language.CQL.Instance.Algebra as A (simplify)
import Language.CQL.Instance.Presentation (Presentation(..))
import qualified Language.CQL.Instance.Presentation as IP (toCollage, typecheck, Presentation(eqs))
import Language.CQL.Mapping as Mapping
Expand Down Expand Up @@ -219,7 +220,7 @@ initialInstance
initialInstance p dp' sch = Instance sch p dp'' $ initialAlgebra
where
dp'' (EQ (lhs, rhs)) = dp' $ EQ (upp lhs, upp rhs)
initialAlgebra = simplifyAlg this
initialAlgebra = A.simplify this
this = Algebra sch en' nf''' nf'''2 id ty' nf'''' repr'''' teqs'
col = IP.toCollage sch p
ens' = assembleGens col (close col dp')
Expand Down Expand Up @@ -260,22 +261,6 @@ assembleSks col ens' = unionWith Set.union sks' $ fromListAccum gens'
sks' = foldr (\(sk,t) m -> Map.insert t (Set.insert (MkTalgGen . Left $ sk) (m ! t)) m) ret $ Map.toList $ csks col
ret = Map.fromSet (const Set.empty) $ ctys col

-- | Inlines type-algebra equations of the form @gen = term@.
-- The hard work is delegated to functions from the 'Term' module.
simplifyAlg
:: (MultiTyMap '[Show, Ord, NFData] '[var, ty, sym, en, fk, att, gen, sk, x, y])
=> Algebra var ty sym en fk att gen sk x y
-> Algebra var ty sym en fk att gen sk x y
simplifyAlg
(Algebra sch en' nf''' nf'''2 repr''' ty' nf'''' repr'''' teqs' ) =
Algebra sch en' nf''' nf'''2 repr''' ty'' nf''''' repr'''' teqs''''
where
teqs'' = Set.map (\x -> (Map.empty, x)) teqs'
(teqs''', f) = simplifyFix teqs'' []
teqs'''' = Set.map snd teqs'''
ty'' t = Set.filter (\x -> notElem (HSk x) $ map fst f) $ ty' t
nf''''' e = replaceRepeatedly f $ nf'''' e

instance NFData InstanceEx where
rnf (InstanceEx x) = rnf x

Expand Down
6 changes: 3 additions & 3 deletions src/Language/CQL/Instance/Algebra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ type Carrier en fk gen = Term Void Void Void en fk Void gen Void
newtype TalgGen en fk att gen sk = MkTalgGen (Either sk (Carrier en fk gen, att))

-- | Inlines type-algebra equations of the form @gen = term@.
-- The hard work is delegated to functions from the 'Term' module.
simplifyAlg
-- The hard work is delegated to functions from the 'Term' module.
simplify
:: (MultiTyMap '[Show, Ord, NFData] '[var, ty, sym, en, fk, att, gen, sk, x, y])
=> Algebra var ty sym en fk att gen sk x y
-> Algebra var ty sym en fk att gen sk x y
simplifyAlg
simplify
(Algebra sch en' nf''' nf'''2 repr''' ty' nf'''' repr'''' teqs' ) =
Algebra sch en' nf''' nf'''2 repr''' ty'' nf''''' repr'''' teqs''''
where
Expand Down

0 comments on commit b7712e6

Please sign in to comment.