getCallback :: [BC] -> [(FDesc, Int)]
getCallback bc = getCallback' (reverse bc)
    where
        getCallback' (x:xs) = case hasCallback x of
                                [] -> getCallback' xs
                                cbs -> case findCons cbs xs of
                                        [] -> error "Idris function couldn't be wrapped."
                                        x -> x
        getCallback' [] = []
        findCons (c:cs) xs = findCon c xs ++ findCons cs xs
        findCons [] _ = []
        findCon c ((MKCON l loc tag args):xs) | snd c == l = [(fst c, tag)]
        findCon c (_:xs) = findCon c xs
        findCon c [] = []
getCallback :: [BC] -> [(FDesc, Int)]
getCallback bc = getCallback' (reverse bc)
    where
        getCallback' (x:xs) = case hasCallback x of
                                [] -> getCallback' xs
                                cbs -> case findCons cbs xs of
                                        [] -> error "Idris function couldn't be wrapped."
                                        x -> x
        getCallback' [] = []
        findCons (c:cs) xs = findCon c xs ++ findCons cs xs
        findCons [] _ = []
        findCon c ((MKCON l loc tag args):xs) | snd c == l = [(fst c, tag)]
        findCon c (_:xs) = findCon c xs
        findCon c [] = []
getCallback bc = getCallback' (reverse bc)
    where
        getCallback' (x:xs) = case hasCallback x of
                                [] -> getCallback' xs
                                cbs -> case findCons cbs xs of
                                        [] -> error "Idris function couldn't be wrapped."
                                        x -> x
        getCallback' [] = []
        findCons (c:cs) xs = findCon c xs ++ findCons cs xs
        findCons [] _ = []
        findCon c ((MKCON l loc tag args):xs) | snd c == l = [(fst c, tag)]
        findCon c (_:xs) = findCon c xs
        findCon c [] = []