typeLinkingExpr db imps su (CastA casttp dim expr _) = case typeExpr of
                                                        [] -> typeLinkingFailure $ "CastA: cannot type linking the expression " ++ (show expr)
                                                        [tp] -> if null $ castConversion db tp targetType then typeLinkingFailure $ "CastA: cannot make the cast " ++ (show tp) ++ (show targetType) else [targetType]
                                                        tps -> typeLinkingFailure $ "CastA: expression have multi types " ++ (show expr) ++ (show tps)
        where
            typeExpr = typeLinkingExpr db imps su expr
            targetType = if dim == Null then casttp else (Array casttp)

-- to do: is it possible cast from A to B?
typeLinkingExpr db imps su (CastA casttp dim expr _) = case typeExpr of
                                                        [] -> typeLinkingFailure $ "CastA: cannot type linking the expression " ++ (show expr)
                                                        [tp] -> if null $ castConversion db tp targetType then typeLinkingFailure $ "CastA: cannot make the cast " ++ (show tp) ++ (show targetType) else [targetType]
                                                        tps -> typeLinkingFailure $ "CastA: expression have multi types " ++ (show expr) ++ (show tps)
        where
            typeExpr = typeLinkingExpr db imps su expr
            targetType = if dim == Null then casttp else (Array casttp)

-- to do: is it possible cast from A to B?
typeLinkingExpr db imps su (CastA casttp dim expr _) = case typeExpr of
                                                        [] -> typeLinkingFailure $ "CastA: cannot type linking the expression " ++ (show expr)
                                                        [tp] -> if null $ castConversion db tp targetType then typeLinkingFailure $ "CastA: cannot make the cast " ++ (show tp) ++ (show targetType) else [targetType]
                                                        tps -> typeLinkingFailure $ "CastA: expression have multi types " ++ (show expr) ++ (show tps)
        where
            typeExpr = typeLinkingExpr db imps su expr
            targetType = if dim == Null then casttp else (Array casttp)

-- to do: is it possible cast from A to B?