-- * analyse kinds

-- | check the kind and compute the raw kind
anaKindM :: Kind -> ClassMap -> Result RawKind
anaKindM k cm = case k of
    ClassKind ci -> if k == universe then return rStar
       else case Map.lookup ci cm of
            Just (ClassInfo rk _) -> return rk
            Nothing -> Result [mkDiag Error "not a class" ci] $ Just rStar
    FunKind v k1 k2 ps -> do
        rk1 <- anaKindM k1 cm
        rk2 <- anaKindM k2 cm
        return $ FunKind v rk1 rk2 ps

-- | get minimal function kinds of (class) kind
anaKindM :: Kind -> ClassMap -> Result RawKind
anaKindM k cm = case k of
    ClassKind ci -> if k == universe then return rStar
       else case Map.lookup ci cm of
            Just (ClassInfo rk _) -> return rk
            Nothing -> Result [mkDiag Error "not a class" ci] $ Just rStar
    FunKind v k1 k2 ps -> do
        rk1 <- anaKindM k1 cm
        rk2 <- anaKindM k2 cm
        return $ FunKind v rk1 rk2 ps

-- | get minimal function kinds of (class) kind
anaKindM k cm = case k of
    ClassKind ci -> if k == universe then return rStar
       else case Map.lookup ci cm of
            Just (ClassInfo rk _) -> return rk
            Nothing -> Result [mkDiag Error "not a class" ci] $ Just rStar
    FunKind v k1 k2 ps -> do
        rk1 <- anaKindM k1 cm
        rk2 <- anaKindM k2 cm
        return $ FunKind v rk1 rk2 ps

-- | get minimal function kinds of (class) kind