Overload.hs revision b32596e241446281ecf820b277f5b85466f99821
ea9ad77838dce923ced1df2ac09a7f0226363593Christian MaederModule : $Header$
ea9ad77838dce923ced1df2ac09a7f0226363593Christian MaederDescription : Overload resolution
ea9ad77838dce923ced1df2ac09a7f0226363593Christian MaederCopyright : (c) Martin Kuehl, T. Mossakowski, C. Maeder, 2004-2007
97018cf5fa25b494adffd7e9b4e87320dae6bf47Christian MaederLicense : GPLv2 or higher, see LICENSE.txt
b4fbc96e05117839ca409f5f20f97b3ac872d1edTill MossakowskiMaintainer : Christian.Maeder@dfki.de
ea9ad77838dce923ced1df2ac09a7f0226363593Christian MaederStability : provisional
ea9ad77838dce923ced1df2ac09a7f0226363593Christian MaederPortability : portable
f3a94a197960e548ecd6520bb768cb0d547457bbChristian MaederOverload resolution (injections are inserted separately)
bc67ede91ef5309852f1ba3a5a0d6b429f405e9dChristian Maeder Follows Sect. III:3.3 of the CASL Reference Manual.
bc67ede91ef5309852f1ba3a5a0d6b429f405e9dChristian Maeder The algorthim is from:
ea9ad77838dce923ced1df2ac09a7f0226363593Christian Maeder Till Mossakowski, Kolyang, Bernd Krieg-Brueckner:
bc67ede91ef5309852f1ba3a5a0d6b429f405e9dChristian Maeder Static semantic analysis and theorem proving for CASL.
93fa7e4374de6e37328e752991a698bf03032c75Christian Maeder 12th Workshop on Algebraic Development Techniques, Tarquinia 1997,
93fa7e4374de6e37328e752991a698bf03032c75Christian Maeder LNCS 1376, p. 333-348
2eb84fc82d3ffa9116bc471fda3742bd9e5a24bbChristian Maeder ( minExpFORMULA
2eb84fc82d3ffa9116bc471fda3742bd9e5a24bbChristian Maeder , minExpFORMULAeq
2eb84fc82d3ffa9116bc471fda3742bd9e5a24bbChristian Maeder , isUnambiguous
1f086d5155f47fdad9a0de4e46bbebb2c4b33d30Christian Maeder , minimalSupers
9963c741a47c42d2dedc6e4589c1b197129a6239Christian Maeder , maximalSubs
eed6203a39f88e398d86431a66d367036a3d17baChristian Maeder , haveCommonSupersorts
feb3da029bdab54fe36ff704ca242ab4536b3bc1Christian Maeder , haveCommonSubsorts
eed6203a39f88e398d86431a66d367036a3d17baChristian Maeder , keepMinimals1
9963c741a47c42d2dedc6e4589c1b197129a6239Christian Maeder , keepMinimals
feb3da029bdab54fe36ff704ca242ab4536b3bc1Christian Maederimport CASL.ToDoc (FormExtension)
71de4b92b1ca12890a9e7bc5b0301455da3e052fChristian Maederimport qualified Common.Lib.MapSet as MapSet
62198789c7cb57cac13399055515921c0fe3483fChristian Maederimport qualified Common.Lib.Rel as Rel
906f0b21e2dc78ee4f37f879518be018a0204cd9Christian Maederimport qualified Data.Map as Map
feb3da029bdab54fe36ff704ca242ab4536b3bc1Christian Maederimport qualified Data.Set as Set
feb3da029bdab54fe36ff704ca242ab4536b3bc1Christian Maeder-- | the type of the type checking function of extensions
feb3da029bdab54fe36ff704ca242ab4536b3bc1Christian Maedertype Min f e = Sign f e -> f -> Result f
feb3da029bdab54fe36ff704ca242ab4536b3bc1Christian MaedermkSorted :: TermExtension f => Sign f e -> TERM f -> SORT -> Range -> TERM f
eed6203a39f88e398d86431a66d367036a3d17baChristian MaedermkSorted sign t s r = let nt = Sorted_term t s r in case optTermSort t of
eed6203a39f88e398d86431a66d367036a3d17baChristian Maeder Nothing -> nt
eed6203a39f88e398d86431a66d367036a3d17baChristian Maeder Just srt -> if leqSort sign s srt then t else nt
eed6203a39f88e398d86431a66d367036a3d17baChristian Maeder{- ----------------------------------------------------------
feb3da029bdab54fe36ff704ca242ab4536b3bc1Christian Maeder - Minimal expansion of a formula -
eed6203a39f88e398d86431a66d367036a3d17baChristian Maeder Expand a given formula by typing information.
eed6203a39f88e398d86431a66d367036a3d17baChristian Maeder * For non-atomic formulae, recurse through subsentences.
eed6203a39f88e398d86431a66d367036a3d17baChristian Maeder * For trival atomic formulae, no expansion is neccessary.
9963c741a47c42d2dedc6e4589c1b197129a6239Christian Maeder * For atomic formulae, the following cases are implemented:
9963c741a47c42d2dedc6e4589c1b197129a6239Christian Maeder + Predication is handled by the dedicated expansion function
42c01284bba8d7c8d995c8dfb96ace57d28ed1bcTill Mossakowski 'minExpFORMULApred'.
9963c741a47c42d2dedc6e4589c1b197129a6239Christian Maeder + Existl_equation and Strong_equation are handled by the dedicated
9963c741a47c42d2dedc6e4589c1b197129a6239Christian Maeder expansion function 'minExpFORMULAeq'.
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder + Definedness is handled by expanding the subterm.
42c01284bba8d7c8d995c8dfb96ace57d28ed1bcTill Mossakowski + Membership is handled like Cast
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder---------------------------------------------------------- -}
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder :: (FormExtension f, TermExtension f)
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder => Min f e -> Sign f e -> FORMULA f -> Result (FORMULA f)
42c01284bba8d7c8d995c8dfb96ace57d28ed1bcTill MossakowskiminExpFORMULA mef sign formula = let sign0 = sign { envDiags = [] } in
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder case formula of
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder Quantification q vars f pos -> do
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder -- add 'vars' to signature
42c01284bba8d7c8d995c8dfb96ace57d28ed1bcTill Mossakowski let sign' = execState (mapM_ addVars vars) sign0
9963c741a47c42d2dedc6e4589c1b197129a6239Christian Maeder Result (envDiags sign') $ Just ()
9963c741a47c42d2dedc6e4589c1b197129a6239Christian Maeder f' <- minExpFORMULA mef sign' f
42c01284bba8d7c8d995c8dfb96ace57d28ed1bcTill Mossakowski return (Quantification q vars f' pos)
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder Junction j fs pos -> do
42c01284bba8d7c8d995c8dfb96ace57d28ed1bcTill Mossakowski fs' <- mapR (minExpFORMULA mef sign) fs
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder return (Junction j fs' pos)
9963c741a47c42d2dedc6e4589c1b197129a6239Christian Maeder Relation f1 c f2 pos ->
9963c741a47c42d2dedc6e4589c1b197129a6239Christian Maeder joinResultWith (\ f1' f2' -> Relation f1' c f2' pos)
42c01284bba8d7c8d995c8dfb96ace57d28ed1bcTill Mossakowski (minExpFORMULA mef sign f1) $ minExpFORMULA mef sign f2
71de4b92b1ca12890a9e7bc5b0301455da3e052fChristian Maeder Negation f pos -> do
feb3da029bdab54fe36ff704ca242ab4536b3bc1Christian Maeder f' <- minExpFORMULA mef sign f
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder return (Negation f' pos)
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder Predication (Pred_name ide) terms pos
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder -> minExpFORMULApred mef sign ide Nothing terms pos
42c01284bba8d7c8d995c8dfb96ace57d28ed1bcTill Mossakowski Predication (Qual_pred_name ide ty pos1) terms pos2
42c01284bba8d7c8d995c8dfb96ace57d28ed1bcTill Mossakowski -> minExpFORMULApred mef sign ide (Just $ toPredType ty)
42c01284bba8d7c8d995c8dfb96ace57d28ed1bcTill Mossakowski terms (pos1 `appRange` pos2)
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder Equation term1 e term2 pos
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder -> minExpFORMULAeq mef sign (`Equation` e) term1 term2 pos
42c01284bba8d7c8d995c8dfb96ace57d28ed1bcTill Mossakowski Definedness term pos -> do
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder t <- oneExpTerm mef sign term
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder return (Definedness t pos)
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder Membership term srt pos -> do
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder ts <- minExpTerm mef sign term
14327755c1e6236e5a23594980a4b82bdce4d0a0Christian Maeder let fs = map (concatMap ( \ t ->
690f3a0b5f77633547e0a797c96b005a5f6ae56cChristian Maeder Membership (mkSorted sign t c pos) srt pos)
1f086d5155f47fdad9a0de4e46bbebb2c4b33d30Christian Maeder $ maybe [srt] (minimalSupers sign srt)
9963c741a47c42d2dedc6e4589c1b197129a6239Christian Maeder $ optTermSort t)) ts
9963c741a47c42d2dedc6e4589c1b197129a6239Christian Maeder isUnambiguous "" (globAnnos sign) formula fs pos
9963c741a47c42d2dedc6e4589c1b197129a6239Christian Maeder ExtFORMULA f -> fmap ExtFORMULA $ mef sign f
9963c741a47c42d2dedc6e4589c1b197129a6239Christian Maeder QuantOp o ty f -> do
9963c741a47c42d2dedc6e4589c1b197129a6239Christian Maeder let sign' = sign0 { opMap = addOpTo o (toOpType ty) $ opMap sign0 }
9963c741a47c42d2dedc6e4589c1b197129a6239Christian Maeder Result (envDiags sign') $ Just ()
71de4b92b1ca12890a9e7bc5b0301455da3e052fChristian Maeder f' <- minExpFORMULA mef sign' f
feb3da029bdab54fe36ff704ca242ab4536b3bc1Christian Maeder return $ QuantOp o ty f'
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder QuantPred p ty f -> do
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder let pm = predMap sign0
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder sign' = sign0
0af0cffad0fea46df86ff9a9b1d490247871719aChristian Maeder { predMap = MapSet.insert p (toPredType ty) pm }
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder Result (envDiags sign') $ Just ()
0af0cffad0fea46df86ff9a9b1d490247871719aChristian Maeder f' <- minExpFORMULA mef sign' f
0af0cffad0fea46df86ff9a9b1d490247871719aChristian Maeder return $ QuantPred p ty f'
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder Mixfix_formula term -> do
eed6203a39f88e398d86431a66d367036a3d17baChristian Maeder t <- oneExpTerm mef sign term
0af0cffad0fea46df86ff9a9b1d490247871719aChristian Maeder let Result ds mt = adjustPos (getRangeSpan term) $ termToFormula t
190828a6ce12ff8c502e3d7303dcc0d70db49b6cChristian Maeder appendDiags ds
190828a6ce12ff8c502e3d7303dcc0d70db49b6cChristian Maeder Nothing -> mkError "not a formula" term
ab7a0615fceecfe401c3229ce7147d2bafc80287Christian Maeder Just f -> return f
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder _ -> return formula -- do not fail even for unresolved cases
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder-- | test if a term can be uniquely resolved
a255351561838b3743d03c1629d335cfb8b83804Christian MaederoneExpTerm :: (FormExtension f, TermExtension f)
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder => Min f e -> Sign f e -> TERM f -> Result (TERM f)
a255351561838b3743d03c1629d335cfb8b83804Christian MaederoneExpTerm minF sign term = do
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder ts <- minExpTerm minF sign term
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder isUnambiguous "" (globAnnos sign) term ts nullRange
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder{- ----------------------------------------------------------
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder - Minimal expansion of an equation formula -
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder see minExpTermCond
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder---------------------------------------------------------- -}
190828a6ce12ff8c502e3d7303dcc0d70db49b6cChristian MaederminExpFORMULAeq :: (FormExtension f, TermExtension f)
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder => Min f e -> Sign f e -> (TERM f -> TERM f -> Range -> FORMULA f)
0af0cffad0fea46df86ff9a9b1d490247871719aChristian Maeder -> TERM f -> TERM f -> Range -> Result (FORMULA f)
a255351561838b3743d03c1629d335cfb8b83804Christian MaederminExpFORMULAeq mef sign eq term1 term2 pos = do
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder ps <- minExpTermCond mef sign ( \ t1 t2 -> eq t1 t2 pos)
190828a6ce12ff8c502e3d7303dcc0d70db49b6cChristian Maeder term1 term2 pos
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder isUnambiguous "" (globAnnos sign) (eq term1 term2 pos) ps pos
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder-- | check if there is at least one solution
a255351561838b3743d03c1629d335cfb8b83804Christian MaederhasSolutions :: Pretty f => String -> GlobalAnnos -> f -> [[f]] -> Range
95936ba3a6577d40aae065aafac4147f5a308782Christian Maeder -> Result [[f]]
a255351561838b3743d03c1629d335cfb8b83804Christian MaederhasSolutions msg ga topterm ts pos = let terms = filter (not . null) ts in
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder if null terms then Result
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder [Diag Error ("no typing for: " ++ showGlobalDoc ga topterm "" ++ msg)
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder else return terms
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder-- | check if there is a unique equivalence class
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian MaederisUnambiguous :: Pretty f => String -> GlobalAnnos -> f -> [[f]] -> Range
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian MaederisUnambiguous msg ga topterm ts pos = do
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder terms <- hasSolutions msg ga topterm ts pos
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder case terms of
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder [ term : _ ] -> return term
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder _ -> Result [Diag Error ("ambiguous term\n " ++
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder showSepList (showString "\n ") (showGlobalDoc ga)
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder (take 5 $ map head terms) "") pos] Nothing
26d3a8da6b4244d65614b5585927df4948e542a0Christian MaedercheckIdAndArgs :: Id -> [a] -> Range -> Result Int
26d3a8da6b4244d65614b5585927df4948e542a0Christian MaedercheckIdAndArgs ide args poss =
26d3a8da6b4244d65614b5585927df4948e542a0Christian Maeder let nargs = length args
26d3a8da6b4244d65614b5585927df4948e542a0Christian Maeder pargs = placeCount ide
26d3a8da6b4244d65614b5585927df4948e542a0Christian Maeder in if isMixfix ide && pargs /= nargs then
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder Result [Diag Error
3f0cd3e73a8aa47bb586b69fe5f7fa450000ecfdChristian Maeder ("expected " ++ shows pargs " argument(s) of mixfix identifier '"
dd836737068504898d4f7843ebd8a3df05f3067dChristian Maeder ++ showDoc ide "' but found " ++ shows nargs " argument(s)")
690f3a0b5f77633547e0a797c96b005a5f6ae56cChristian Maeder poss] Nothing
690f3a0b5f77633547e0a797c96b005a5f6ae56cChristian Maeder else return nargs
690f3a0b5f77633547e0a797c96b005a5f6ae56cChristian MaedernoOpOrPredDiag :: Pretty t => [a] -> DiagKind -> String -> Maybe t -> Id
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder -> Range -> Int -> [Diagnosis]
0af0cffad0fea46df86ff9a9b1d490247871719aChristian MaedernoOpOrPredDiag ops k str mty ide pos nargs = case ops of
0af0cffad0fea46df86ff9a9b1d490247871719aChristian Maeder hd = "no " ++ str ++ " with "
0af0cffad0fea46df86ff9a9b1d490247871719aChristian Maeder ft = " found for '" ++ showDoc ide "'"
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder in [Diag k (case mty of
690f3a0b5f77633547e0a797c96b005a5f6ae56cChristian Maeder Nothing -> hd ++ shows nargs " argument"
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder ++ (if nargs == 1 then "" else "s") ++ ft
0af0cffad0fea46df86ff9a9b1d490247871719aChristian Maeder Just ty -> hd ++ "profile '" ++ showDoc ty "'" ++ ft) pos]
0af0cffad0fea46df86ff9a9b1d490247871719aChristian MaedernoOpOrPred :: Pretty t => [a] -> String -> Maybe t -> Id -> Range -> Int
9256f871e7dd915ccfb5969e2117f054306cd366Christian MaedernoOpOrPred ops str mty ide pos nargs = when (null ops) $ Result
0af0cffad0fea46df86ff9a9b1d490247871719aChristian Maeder (noOpOrPredDiag ops Error str mty ide pos nargs) Nothing
0af0cffad0fea46df86ff9a9b1d490247871719aChristian Maeder{- ----------------------------------------------------------
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder - Minimal expansion of a predication formula -
0af0cffad0fea46df86ff9a9b1d490247871719aChristian Maeder see minExpTermAppl
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder---------------------------------------------------------- -}
0af0cffad0fea46df86ff9a9b1d490247871719aChristian MaederminExpFORMULApred :: (FormExtension f, TermExtension f)
0af0cffad0fea46df86ff9a9b1d490247871719aChristian Maeder => Min f e -> Sign f e -> Id -> Maybe PredType -> [TERM f] -> Range
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder -> Result (FORMULA f)
690f3a0b5f77633547e0a797c96b005a5f6ae56cChristian MaederminExpFORMULApred mef sign ide mty args pos = do
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder nargs <- checkIdAndArgs ide args pos
0af0cffad0fea46df86ff9a9b1d490247871719aChristian Maeder let -- predicates matching that name in the current environment
0af0cffad0fea46df86ff9a9b1d490247871719aChristian Maeder preds' = Set.filter ((nargs ==) . length . predArgs) $
0af0cffad0fea46df86ff9a9b1d490247871719aChristian Maeder MapSet.lookup ide $ predMap sign
0af0cffad0fea46df86ff9a9b1d490247871719aChristian Maeder preds = case mty of
190828a6ce12ff8c502e3d7303dcc0d70db49b6cChristian Maeder Nothing -> map (pSortBy predArgs sign)
190828a6ce12ff8c502e3d7303dcc0d70db49b6cChristian Maeder $ Rel.leqClasses (leqP' sign) preds'
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder Just ty -> [[ty] | Set.member ty preds']
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder boolAna l cmd = case mty of
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder Nothing | null l -> do
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder appendDiags $ noOpOrPredDiag preds Hint
bc67ede91ef5309852f1ba3a5a0d6b429f405e9dChristian Maeder "matching predicate" mty ide pos nargs
0af0cffad0fea46df86ff9a9b1d490247871719aChristian Maeder minExpFORMULA mef sign $ Mixfix_formula
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder $ Application (Op_name ide) args pos
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder boolAna preds $ do
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder noOpOrPred preds "predicate" mty ide pos nargs
190828a6ce12ff8c502e3d7303dcc0d70db49b6cChristian Maeder expansions <- mapM (minExpTerm mef sign) args
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder let formCombs = concatMap (getCombs sign predArgs preds . combine)
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder $ combine expansions
1f086d5155f47fdad9a0de4e46bbebb2c4b33d30Christian Maeder partCombs = map (partition $ \ (_, _, m) -> isNothing m) formCombs
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder (goodCombs, badCombs) = unzip partCombs
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder badCs@(_ : _) = concat badCombs
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder maxArg = maximum $ map (\ (_, _, Just c) -> c) badCs
190828a6ce12ff8c502e3d7303dcc0d70db49b6cChristian Maeder badCs2 = filter (\ (_, _, Just c) -> maxArg == c) badCs
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder expectedTs = keepMinimals1 False sign id
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder $ map (\ (a, _, _) -> predArgs a !! maxArg) badCs2
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder foundTs = keepMinimals sign id
190828a6ce12ff8c502e3d7303dcc0d70db49b6cChristian Maeder $ map (\ (_, ts, _) -> sortOfTerm $ ts !! maxArg) badCs2
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder qualForms = qualifyGFs qualifyPred ide pos goodCombs
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder boolAna qualForms
190828a6ce12ff8c502e3d7303dcc0d70db49b6cChristian Maeder $ isUnambiguous (missMsg maxArg ide foundTs expectedTs) (globAnnos sign)
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder (Predication (Pred_name ide) args pos) qualForms pos
190828a6ce12ff8c502e3d7303dcc0d70db49b6cChristian MaedermissMsg :: Int -> Id -> [SORT] -> [SORT] -> String
a255351561838b3743d03c1629d335cfb8b83804Christian MaedermissMsg maxArg ide foundTs expectedTs =
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder let showSort s = case s of
190828a6ce12ff8c502e3d7303dcc0d70db49b6cChristian Maeder [ft] -> "a term of sort '" ++ shows ft "' was "
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder _ -> "terms of sorts " ++ showDoc s " were "
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder "\nin the " ++ show (maxArg + 1) ++ ". argument of '" ++ shows ide "'\n"
190828a6ce12ff8c502e3d7303dcc0d70db49b6cChristian Maeder ++ showSort foundTs ++ "found but\n"
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder ++ showSort expectedTs ++ "expected."
a255351561838b3743d03c1629d335cfb8b83804Christian MaedergetCombs :: TermExtension f => Sign f e -> (a -> [SORT]) -> [[a]] -> [[TERM f]]
190828a6ce12ff8c502e3d7303dcc0d70db49b6cChristian Maeder -> [[(a, [TERM f], Maybe Int)]]
a255351561838b3743d03c1629d335cfb8b83804Christian MaedergetCombs sign getArgs = flip $ map . \ cs fs ->
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder [ (f, ts, elemIndex False $ zipWith (leqSort sign) (map sortOfTerm ts)
190828a6ce12ff8c502e3d7303dcc0d70db49b6cChristian Maeder $ getArgs f) | f <- fs, ts <- cs ]
a255351561838b3743d03c1629d335cfb8b83804Christian MaedergetProfiles :: TermExtension f => Sign f e -> (a -> [SORT]) -> [[a]]
190828a6ce12ff8c502e3d7303dcc0d70db49b6cChristian Maeder -> [[TERM f]] -> [[(a, [TERM f])]]
a255351561838b3743d03c1629d335cfb8b83804Christian MaedergetProfiles sign getArgs = flip $ map . \ cs fs ->
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder [ (f, ts) | f <- fs, ts <- cs
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder , and $ zipWith (leqSort sign) (map sortOfTerm ts) (getArgs f) ]
42c01284bba8d7c8d995c8dfb96ace57d28ed1bcTill MossakowskiqualifyGFs :: (Id -> Range -> (a, [TERM f]) -> b) -> Id -> Range
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder -> [[(a, [TERM f], Maybe Int)]] -> [[b]]
a255351561838b3743d03c1629d335cfb8b83804Christian MaederqualifyGFs f ide pos = map $ map (f ide pos . \ (a, b, _) -> (a, b))
a255351561838b3743d03c1629d335cfb8b83804Christian MaederqualifyFs :: (Id -> Range -> (a, [TERM f]) -> b) -> Id -> Range
0af0cffad0fea46df86ff9a9b1d490247871719aChristian Maeder -> [[(a, [TERM f])]] -> [[b]]
a255351561838b3743d03c1629d335cfb8b83804Christian MaederqualifyFs f ide = map . map . f ide
a255351561838b3743d03c1629d335cfb8b83804Christian Maeder-- | qualify a single pred, given by its signature and its arguments
a255351561838b3743d03c1629d335cfb8b83804Christian MaederqualifyPred :: Id -> Range -> (PredType, [TERM f]) -> FORMULA f
190828a6ce12ff8c502e3d7303dcc0d70db49b6cChristian MaederqualifyPred ide pos (pred', terms') =
minExpTermVar sign tok ms = case Map.lookup tok $ varMap sign of
ops' = Set.filter ( \ o -> length (opArgs o) == nargs) $
MapSet.lookup ide $ opMap sign
$ Rel.leqClasses (leqF' sign) ops'
Just ty -> [[ty] | Set.member ty ops' ||
Set.member (mkTotal ty) ops' ]
if Set.member s2 l1 then if b then [s2] else [s1] else
if Set.member s1 l2 then if b then [s1] else [s2] else
else Set.intersection (subsortsOf s1 sign)
b = Set.member s1 l2 in
if Set.member s2 l1 then