anaAttr :: GlobalAnnos -> TypeScheme -> OpAttr -> State Env (Maybe OpAttr)
anaAttr ga (TypeScheme tvs (_ :=> ty) _) (UnitOpAttr trm ps) =
do let mTy = case unalias ty of
ProductType [t1, t2] _ -> Just (t1,t2,t3)
mapM_ (addTypeVarDecl False) tvs
Nothing -> do addDiags [mkDiag Error
"unexpected type of operation" ty]
mt <- resolveTerm ga Nothing trm
Nothing -> return Nothing
Just t -> return $ Just $ UnitOpAttr t ps
do if t1 == t2 && t2 == t3 then
else addDiags [mkDiag Error
"unexpected type components of operation" ty]
mt <- resolveTerm ga (Just t3) trm
case mt of Nothing -> return Nothing
Just t -> return $ Just $ UnitOpAttr t ps
anaAttr _ _ b = return $ Just b
filterVars :: Assumps -> Assumps
filterVars = filterAssumps (not . isVarDefn)
patternsToType :: [[VarDecl]] -> Type -> Type
patternsToType (p: ps) t = FunType (tuplePatternToType p) PFunArr
tuplePatternToType :: [VarDecl] -> Type
tuplePatternToType vds = mkProductType (map ( \ (VarDecl _ t _ _) -> t) vds) []
getUninstOpId :: TypeScheme -> OpId -> (OpId, TypeScheme)
getUninstOpId (TypeScheme tvs q ps) (OpId i args qs) =
(OpId i [] qs, TypeScheme (args ++ tvs) q ps)
anaOpId :: GlobalAnnos -> OpBrand -> TypeScheme -> [OpAttr] -> OpId
-> State Env (Maybe OpId)
anaOpId ga br partSc attrs o =
do let (OpId i _ _, sc) = getUninstOpId partSc o
Nothing -> return Nothing
mAttrs <- mapM (anaAttr ga newSc) attrs
mo <- addOpId i newSc (catMaybes mAttrs) $ NoOpDefn br
return $ fmap (const o) mo
anaOpItem :: GlobalAnnos -> OpBrand -> OpItem -> State Env OpItem
anaOpItem ga br (OpDecl is sc attr ps) = do
us <- mapM (anaOpId ga br sc attr) is
return $ OpDecl (catMaybes us) sc attr ps
anaOpItem ga br (OpDefn o oldPats sc partial trm ps) =
do let (op@(OpId i _ _), extSc@(TypeScheme tArgs (qu :=> scTy) qs)) =
checkUniqueVars $ concat oldPats
mArgs <- mapM anaTypeVarDecl tArgs
mPats <- mapM (mapM anaVarDecl) oldPats
let newPats = map catMaybes mPats
monoPats = map (map makeMonomorph) newPats
pats = map (\ l -> mkTupleTerm (map QualVar l) []) monoPats
mapM (mapM addVarDecl) monoPats
let newArgs = catMaybes mArgs
checkUniqueTypevars newArgs
mt <- resolveTerm ga (Just ty) trm
mSc <- fromResult $ const $ generalize $
(qu :=> patternsToType newPats ty) qs
(Just lastTrm, Just newSc) -> do
let lamTrm = case (pats, partial) of
_ -> LambdaTerm pats partial lastTrm ps
ot = QualOp br (InstOpId i [] []) newSc []
ef = mkEqTerm eqId ps lhs lastTrm
f = mkForall (map GenTypeVarDecl tArgs
concatMap extractVars pats)) ef
addOpId i newSc [] $ Definition br lamTrm
appendSentences [NamedSen
return $ OpDefn op [] newSc Total lamTrm ps
_ -> return $ OpDefn op newPats extSc partial trm ps
mt <- resolveTerm ga Nothing trm
return $ OpDefn op oldPats extSc partial
(case mt of Nothing -> trm
-- ----------------------------------------------------------------------------
-- ----------------------------------------------------------------------------
anaProgEq :: GlobalAnnos -> ProgEq -> State Env ProgEq
anaProgEq ga pe@(ProgEq pat trm qs) =
mp <- checkPattern ga pat
let exbs = extractVars newPat
mt <- resolveTerm ga Nothing trm
Just newTerm -> let newPrg = ProgEq newPat newTerm qs in
addOpId i sc [] $ NoOpDefn Op
appendSentences [NamedSen ("pe_" ++ showId i "")
if isLHS e newPat then return ()
else addDiags [mkDiag Warning
_ -> do addDiags [mkDiag Error
"illegal toplevel pattern"
_ -> return $ ProgEq newPat trm qs
getApplConstr :: Pattern -> (Pattern, [Pattern])
let (tp, args) = getApplConstr p1 in (tp, p2:args)
TypedTerm tp _ _ _ -> getApplConstr tp