typeLinkingExpr db imps su (CastB castexpr expr _) = if null typeCastExpr || null typeExpr || null casting then typeLinkingFailure "CastB: cannot type linking the expression" else typeCastExpr
        where
            typeCastExpr = case typeLinkingExpr db imps su castexpr of
                            [] -> typeLinkingFailure $ "CastB CastExpr no match " ++ (show castexpr)
                            [TypeClass tp] -> [Object tp]
                            [tp] -> [tp]
                            tps -> typeLinkingFailure $ "CastB CastExpr multi match " ++ (show castexpr) ++ (show tps) ++ (show db)
            typeExpr = case typeLinkingExpr db imps su expr of
                            [] -> typeLinkingFailure $ "CastB Expr no match " ++ (show expr)
                            [tp] -> [tp]
                            tps -> typeLinkingFailure $ "CastB Expr multi match " ++ (show expr) ++ (show tps) ++ (show db)
            casting = case castConversion db (head typeExpr) (head typeCastExpr) of
                            [] -> typeLinkingFailure $ "CastB Casting " ++ (show typeExpr) ++ (show typeCastExpr)
                            tps -> tps

-- to check: must be (Name [])?
typeLinkingExpr db imps su (CastB castexpr expr _) = if null typeCastExpr || null typeExpr || null casting then typeLinkingFailure "CastB: cannot type linking the expression" else typeCastExpr
        where
            typeCastExpr = case typeLinkingExpr db imps su castexpr of
                            [] -> typeLinkingFailure $ "CastB CastExpr no match " ++ (show castexpr)
                            [TypeClass tp] -> [Object tp]
                            [tp] -> [tp]
                            tps -> typeLinkingFailure $ "CastB CastExpr multi match " ++ (show castexpr) ++ (show tps) ++ (show db)
            typeExpr = case typeLinkingExpr db imps su expr of
                            [] -> typeLinkingFailure $ "CastB Expr no match " ++ (show expr)
                            [tp] -> [tp]
                            tps -> typeLinkingFailure $ "CastB Expr multi match " ++ (show expr) ++ (show tps) ++ (show db)
            casting = case castConversion db (head typeExpr) (head typeCastExpr) of
                            [] -> typeLinkingFailure $ "CastB Casting " ++ (show typeExpr) ++ (show typeCastExpr)
                            tps -> tps

-- to check: must be (Name [])?
typeLinkingExpr db imps su (CastB castexpr expr _) = if null typeCastExpr || null typeExpr || null casting then typeLinkingFailure "CastB: cannot type linking the expression" else typeCastExpr
        where
            typeCastExpr = case typeLinkingExpr db imps su castexpr of
                            [] -> typeLinkingFailure $ "CastB CastExpr no match " ++ (show castexpr)
                            [TypeClass tp] -> [Object tp]
                            [tp] -> [tp]
                            tps -> typeLinkingFailure $ "CastB CastExpr multi match " ++ (show castexpr) ++ (show tps) ++ (show db)
            typeExpr = case typeLinkingExpr db imps su expr of
                            [] -> typeLinkingFailure $ "CastB Expr no match " ++ (show expr)
                            [tp] -> [tp]
                            tps -> typeLinkingFailure $ "CastB Expr multi match " ++ (show expr) ++ (show tps) ++ (show db)
            casting = case castConversion db (head typeExpr) (head typeCastExpr) of
                            [] -> typeLinkingFailure $ "CastB Casting " ++ (show typeExpr) ++ (show typeCastExpr)
                            tps -> tps

-- to check: must be (Name [])?