module Curry.AbstractCurry.Files
( readCurry, writeCurry, showCurry
) where
import qualified Control.Exception as C (catch)
import Data.List (intercalate)
import Curry.Files.PathUtils ( writeModule, readModule
, addVersion, checkVersion)
import Curry.AbstractCurry.Type
readCurry :: FilePath -> IO (Maybe CurryProg)
readCurry fn = do
mbSrc <- readModule fn
return $ case mbSrc of
Nothing -> Nothing
Just src -> case checkVersion version src of
Left _ -> Nothing
Right ac -> Just (read ac)
writeCurry :: FilePath -> CurryProg -> IO ()
writeCurry fn p = C.catch (writeModule fn $ addVersion version $ showCurry p)
ioError
showCurry :: CurryProg -> String
showCurry (CurryProg mname imps dflt clss insts types funcs ops)
= "CurryProg " ++ show mname ++ "\n"
++ show imps ++ "\n"
++ showsPrec 11 dflt "\n"
++ wrapList clss
++ wrapList insts
++ wrapList types
++ wrapList funcs
++ wrapList ops
where wrapList xs = " [" ++ intercalate ",\n " (map show xs) ++ "]\n"