{-# OPTIONS_GHC -fglasgow-exts #-} -- -- Copyright (C) 2005 Stefan Wehr - http://www.stefanwehr.de -- -- This program is free software; you can redistribute it and/or -- modify it under the terms of the GNU General Public License as -- published by the Free Software Foundation; either version 2 of -- the License, or (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -- General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software -- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -- 02111-1307, USA. -- module Phrac.Kinds where import Phrac.Symtab import Phrac.AbstractSyntax import Phrac.Error class HasKind t where kindOf :: t -> ST Kind instance HasKind TypeVarId where kindOf id = kindOfTypeVarId id instance HasKind TypeId where kindOf id = do td <- findTypeDef id kindOf td instance HasKind AssocTypeId where kindOf id = do tsig <- findAssocTypeSig id kindOf tsig instance HasKind TypeDef where kindOf td = do paramKinds <- mapM kindOf (tydef_params td) return $ kindFun paramKinds KindStar instance HasKind AssocTypeSig where kindOf (AssocTypeSig id params _) = do paramKinds <- mapM kindOf params return $ kindFun paramKinds KindStar instance HasKind Type where kindOf (TyVar id) = kindOf id kindOf (TyApp t _) = do k <- kindOf t case k of KindFun _ k' -> return k' _ -> panic "illegal kind" kindOf (TyConstruct id) = kindOf id kindOf (TyAssoc at) = kindOf at instance HasKind AssocType where kindOf at = do k <- kindOf (assoc_name at) return $ erase k (assoc_params at) where erase k [] = k erase (KindFun _ k) (x:xs) = erase k xs erase _ _ = panic "illegal kind"