TypeDecl.hs revision 53301de22afd7190981b363b57c48df86fcb50f7
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian MaederModule : $Header$
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian MaederCopyright : (c) Christian Maeder and Uni Bremen 2002-2003
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian MaederLicence : All rights reserved.
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian MaederMaintainer : hets@tzi.de
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian MaederStability : provisional
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian MaederPortability : non-portable (MonadState)
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maederanalyse type decls
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maederimport qualified Common.Lib.Map as Map
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder-- | add a supertype to a given type id
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian MaederaddSuperType :: Type -> Id -> State Env ()
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian MaederaddSuperType t i =
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder do tk <- gets typeMap
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder Nothing -> return () -- previous error
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder Just (TypeInfo ok ks sups defn) ->
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder (TypeInfo ok ks (t:sups) defn)
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian MaederidsToTypePatterns :: [Maybe Id] -> [TypePattern]
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian MaederidsToTypePatterns mis = map ( \ i -> TypePattern i [] [] )
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder $ catMaybes mis
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian MaederanaFormula :: GlobalAnnos -> Annoted Term -> State Env (Maybe (Annoted Term))
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian MaederanaFormula ga at =
186de7a36bdf5910e0616c3a0447603e98217dc7Christian Maeder do mt <- resolveTerm ga (Just logicalType) $ item at
186de7a36bdf5910e0616c3a0447603e98217dc7Christian Maeder return $ case mt of Nothing -> Nothing
186de7a36bdf5910e0616c3a0447603e98217dc7Christian Maeder Just e -> Just at { item = e }
186de7a36bdf5910e0616c3a0447603e98217dc7Christian MaederanaVars :: Vars -> Type -> Result [VarDecl]
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian MaederanaVars (Var v) t = return [VarDecl v t Other []]
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian MaederanaVars (VarTuple vs _) t =
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder ProductType ts _ ->
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder if length ts == length vs then
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder let lrs = zipWith anaVars vs ts
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder lms = map maybeResult lrs in
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder if all isJust lms then
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder return $ concatMap fromJust lms
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder else Result (concatMap diags lrs) Nothing
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder else Result [mkDiag Error "wrong arity" t] Nothing
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder _ -> Result [mkDiag Error "product type expected instead" t] Nothing
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder-- | analyse a 'TypeItem'
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian MaederanaTypeItem :: GlobalAnnos -> GenKind -> Instance -> TypeItem
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder -> State Env TypeItem
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian MaederanaTypeItem _ _ inst (TypeDecl pats kind ps) =
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder do ak <- anaKind kind
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder let Result ds (Just is) = convertTypePatterns pats
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder mis <- mapM (addTypeId NoTypeDefn inst ak) is
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder return $ TypeDecl (idsToTypePatterns mis) ak ps
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian MaederanaTypeItem _ _ inst (SubtypeDecl pats t ps) =
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder do let Result ds (Just is) = convertTypePatterns pats
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder mis <- mapM (addTypeId NoTypeDefn inst star) is
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder let newPats = idsToTypePatterns mis
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder mt <- anaStarType t
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder Nothing -> return $ TypeDecl newPats star ps
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder Just newT -> do mapM_ (addSuperType newT) is
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder return $ SubtypeDecl newPats newT ps
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian MaederanaTypeItem _ _ inst (IsoDecl pats ps) =
52dc3a3b27f1bdd5128c89f96e1a5444a96474d8Christian Maeder do let Result ds (Just is) = convertTypePatterns pats