+myCatch (GHCi m) h = GHCi $ \s -> Exception.catch (m s) (\e -> unGHCi (h e) s)
+
+-----------------------------------------------------------------------------
+-- package loader
+
+linkPackages :: [Package] -> IO ()
+linkPackages pkgs = mapM_ linkPackage pkgs
+
+linkPackage :: Package -> IO ()
+-- ignore rts and gmp for now (ToDo; better?)
+linkPackage pkg | name pkg `elem` ["rts", "gmp"] = return ()
+linkPackage pkg = do
+ putStr ("Loading package " ++ name pkg ++ " ... ")
+ let dirs = library_dirs pkg
+ let objs = map (++".o") (hs_libraries pkg ++ extra_libraries pkg)
+ mapM (linkOneObj dirs) objs
+ putStr "resolving ... "
+ resolveObjs
+ putStrLn "done."
+
+linkOneObj dirs obj = do
+ filename <- findFile dirs obj
+ loadObj filename
+
+findFile [] obj = throwDyn (OtherError ("can't find " ++ obj))
+findFile (d:ds) obj = do
+ let path = d ++ '/':obj
+ b <- doesFileExist path
+ if b then return path else findFile ds obj
+
+