[library cleanups, start moving type declarations to Jhc.Type
John Meacham <john@repetae.net>**20120123135418
 Ignore-this: 97b36c5e33a94b244baa76e08b7efdb5
] hunk ./lib/base/System/IO/Error.hs 2
-
-    -- * I\/O errors
-    IOError,
-    userError,		       	-- :: String  -> IOError
-    --mkIOError,			-- :: IOErrorType -> String -> Maybe Handle
-				--    -> Maybe FilePath -> IOError
-
-    -- ** Classifying I\/O errors
-    isAlreadyExistsError,	-- :: IOError -> Bool
-    isDoesNotExistError,
-    isAlreadyInUseError,
-    isFullError,
-    isEOFError,
-    isIllegalOperation,
-    isPermissionError,
-    isUserError,
-
-    -- * Throwing and catching I\/O errors
-
-    ioError,		       	-- :: IOError -> IO a
-
-    catch,			-- :: IO a -> (IOError -> IO a) -> IO a
-    try,			-- :: IO a -> IO (Either IOError a)
-    ioeGetErrorString,
-    ioeGetFileName,
-    ioeGetHandle,
-
-    modifyIOError		-- :: (IOError -> IOError) -> IO a -> IO a
+    IOError(),  userError,  mkIOError,  annotateIOError,  isAlreadyExistsError,
+    isDoesNotExistError,  isAlreadyInUseError,  isFullError,  isEOFError,
+    isIllegalOperation,  isPermissionError,  isUserError,  ioeGetErrorString,
+    ioeGetHandle,  ioeGetFileName,  IOErrorType(),  alreadyExistsErrorType,
+    doesNotExistErrorType,  alreadyInUseErrorType,  fullErrorType,
+    eofErrorType,  illegalOperationErrorType,  permissionErrorType,
+    userErrorType,  ioError,  catch,  try
hunk ./lib/base/System/IO/Error.hs 13
-
-
-
+import Jhc.Type.Handle
hunk ./lib/base/System/IO/Error.hs 33
---mkIOError :: IOErrorType -> String -> Maybe Handle -> Maybe FilePath -> IOError
---mkIOError = error "mkIOError"
+mkIOError :: IOErrorType -> String -> Maybe Handle -> Maybe FilePath -> IOError
+mkIOError = IOError
hunk ./lib/base/System/IO/Error.hs 36
--- -----------------------------------------------------------------------------
--- IOErrorType
+-- TODO(john): fix
+annotateIOError :: IOError -> String -> Maybe Handle -> Maybe FilePath -> IOError
+annotateIOError ioe _s _mh _mfp = ioe
+
+check :: IOErrorType -> IOError -> Bool
+check errorType ioe = ioeGetErrorType ioe == errorType
hunk ./lib/base/System/IO/Error.hs 46
-isAlreadyExistsError = isAlreadyExistsErrorType    . ioeGetErrorType
+isAlreadyExistsError = check AlreadyExists
hunk ./lib/base/System/IO/Error.hs 51
-isDoesNotExistError  = isDoesNotExistErrorType     . ioeGetErrorType
+isDoesNotExistError  = check DoesNotExist
hunk ./lib/base/System/IO/Error.hs 58
-isAlreadyInUseError  = isAlreadyInUseErrorType     . ioeGetErrorType
+isAlreadyInUseError  = check AlreadyInUse
hunk ./lib/base/System/IO/Error.hs 63
-isFullError          = isFullErrorType             . ioeGetErrorType
+isFullError          = check Full
hunk ./lib/base/System/IO/Error.hs 68
-isEOFError           = isEOFErrorType              . ioeGetErrorType
+isEOFError           = check EOF
hunk ./lib/base/System/IO/Error.hs 77
-isIllegalOperation   = isIllegalOperationErrorType . ioeGetErrorType
+isIllegalOperation   = check IllegalOperation
hunk ./lib/base/System/IO/Error.hs 83
-isPermissionError    = isPermissionErrorType       . ioeGetErrorType
+isPermissionError    = check Permission
hunk ./lib/base/System/IO/Error.hs 87
-isUserError          = isUserErrorType             . ioeGetErrorType
+isUserError          = check User
hunk ./lib/base/System/IO/Error.hs 89
--- -----------------------------------------------------------------------------
--- IOErrorTypes
+deriving instance Eq IOErrorType
+deriving instance Ord IOErrorType
hunk ./lib/base/System/IO/Error.hs 92
-data IOErrorType = AlreadyExists | NoSuchThing | ResourceBusy
-		 | ResourceExhausted | EOF | IllegalOperation
-		 | PermissionDenied | UserError
-                 deriving(Eq,Ord)
+alreadyExistsErrorType = AlreadyExists
+doesNotExistErrorType = DoesNotExist
+alreadyInUseErrorType = AlreadyInUse
+fullErrorType = Full
+eofErrorType = EOF
+illegalOperationErrorType = IllegalOperation
+permissionErrorType = Permission
+userErrorType = User
hunk ./lib/base/System/IO/Error.hs 102
-    showsPrec _ s = showString (showIOError s)
-
--- -----------------------------------------------------------------------------
--- IOErrorType predicates
-
--- | I\/O error where the operation failed because one of its arguments
--- already exists.
-isAlreadyExistsErrorType :: IOErrorType -> Bool
-isAlreadyExistsErrorType AlreadyExists = True
-isAlreadyExistsErrorType _ = False
-
--- | I\/O error where the operation failed because one of its arguments
--- does not exist.
-isDoesNotExistErrorType :: IOErrorType -> Bool
-isDoesNotExistErrorType NoSuchThing = True
-isDoesNotExistErrorType _ = False
-
--- | I\/O error where the operation failed because one of its arguments
--- is a single-use resource, which is already being used.
-isAlreadyInUseErrorType :: IOErrorType -> Bool
-isAlreadyInUseErrorType ResourceBusy = True
-isAlreadyInUseErrorType _ = False
-
--- | I\/O error where the operation failed because the device is full.
-isFullErrorType :: IOErrorType -> Bool
-isFullErrorType ResourceExhausted = True
-isFullErrorType _ = False
-
--- | I\/O error where the operation failed because the end of file has
--- been reached.
-isEOFErrorType :: IOErrorType -> Bool
-isEOFErrorType EOF = True
-isEOFErrorType _ = False
-
--- | I\/O error where the operation is not possible.
-isIllegalOperationErrorType :: IOErrorType -> Bool
-isIllegalOperationErrorType IllegalOperation = True
-isIllegalOperationErrorType _ = False
-
--- | I\/O error where the operation failed because the user does not
--- have sufficient operating system privilege to perform that operation.
-isPermissionErrorType :: IOErrorType -> Bool
-isPermissionErrorType PermissionDenied = True
-isPermissionErrorType _ = False
-
--- | I\/O error that is programmer-defined.
-isUserErrorType :: IOErrorType -> Bool
-isUserErrorType UserError = True
-isUserErrorType _ = False
-
--- -----------------------------------------------------------------------------
--- Miscellaneous
-
--- | Catch any 'IOError' that occurs in the computation and throw a
--- modified version.
-modifyIOError :: (IOError -> IOError) -> IO a -> IO a
-modifyIOError f io = catch io (\e -> ioError (f e))
-
-ioeGetErrorType	      :: IOError -> IOErrorType
-ioeGetErrorType _ = UserError
-
-ioeGetHandle _ = error "ioeGetHandle"
-ioeGetHandle _ = error "ioeGetHandle"
-
-ioeGetErrorString s = showIOError s
-ioeGetFileName _ = error "ioeGetFileName"
-
-
+    showsPrec _ s = (ioeGetErrorString s ++)
hunk ./lib/jhc/Data/Char.hs 19
-import Data.Word(Word())
+--import Data.Word(Word())
hunk ./lib/jhc/Foreign/C/Types.hs 25
-data CFile
hunk ./lib/jhc/Jhc/Addr.hs 18
+import Jhc.Type.Ptr
hunk ./lib/jhc/Jhc/Addr.hs 22
-data Ptr a = Ptr BitsPtr_
-data FunPtr a = FunPtr BitsPtr_
-
hunk ./lib/jhc/Jhc/Handle.hs 29
+import Jhc.Type.Handle
hunk ./lib/jhc/Jhc/Handle.hs 35
+deriving instance Eq IOMode
+deriving instance Ord IOMode
+deriving instance Enum IOMode
+--deriving instance Bounded IOMode
hunk ./lib/jhc/Jhc/Handle.hs 40
-
-data IOMode = ReadMode | WriteMode | AppendMode | ReadWriteMode
-    deriving(Eq, Ord, Bounded, Enum, Show)
-
-
-data Handle = Handle {
-    handleName :: String,
-    handleFile :: !(Ptr FILE),
-    handleBinary :: !Bool,
-    handleIsPipe :: !Bool,
-    handleIOMode :: !IOMode
-    }
+instance Show IOMode where
+    show ReadMode = "ReadMode"
+    show WriteMode = "WriteMode"
+    show AppendMode = "AppendMode"
+    show ReadWriteMode = "ReadWriteMode"
hunk ./lib/jhc/Jhc/Handle.hs 57
-{-
-stdin  = Handle (unsafePerformIO (peek c_stdin))
-stdout = Handle (unsafePerformIO (peek c_stdout))
-stderr = Handle (unsafePerformIO (peek c_stderr))
--}
-
hunk ./lib/jhc/Jhc/IO.hs 25
-    showIOError,
hunk ./lib/jhc/Jhc/IO.hs 35
+import Jhc.Type.Basic
+import Jhc.Type.Handle
hunk ./lib/jhc/Jhc/IO.hs 39
--- basic types
-
hunk ./lib/jhc/Jhc/IO.hs 72
--- IO Exception handling
-
-newtype IOError = IOError String
-    deriving(Eq)
-
-showIOError :: IOError -> String
-showIOError (IOError x) = x
-
-userError       :: String  -> IOError
-userError str	=  IOError  str
-
hunk ./lib/jhc/Jhc/IO.hs 73
-showError (IOError z) = putErrLn z `thenIO_` exitFailure
+--showError (IOError z) = putErrLn z `thenIO_` exitFailure
+showError ioe = putErrLn (ioeGetErrorString ioe) `thenIO_` exitFailure
+
+userError x = IOError User x Nothing Nothing
hunk ./lib/jhc/Jhc/IO.hs 122
-            putErrLn (showIOError e)         `thenIO_`
+            putErrLn (ioeGetErrorString e)   `thenIO_`
hunk ./lib/jhc/Jhc/Maybe.hs 2
-module Jhc.Maybe where
+module Jhc.Maybe(Maybe(..), module Jhc.Maybe) where
hunk ./lib/jhc/Jhc/Maybe.hs 10
+import Jhc.Type.Basic
hunk ./lib/jhc/Jhc/Maybe.hs 18
-
-
hunk ./lib/jhc/Jhc/Maybe.hs 22
+instance Eq a => Eq (Maybe a) where
+    Nothing == Nothing = True
+    Just x == Just y = x == y
+    _ == _ = False
hunk ./lib/jhc/Jhc/Maybe.hs 27
+instance Show a => Show (Maybe a) where
+    showsPrec d (Just m) = showParen (d > app_prec) $
+             showString "Just " . showsPrec (app_prec+1) m
+          where app_prec = 10
+    showsPrec _ Nothing = showString "Nothing"
hunk ./lib/jhc/Jhc/Maybe.hs 33
--- Maybe
--- need to add Read instance
-
-data Maybe a  =  Nothing | Just a
-    deriving (Eq, Ord, Show)
+instance Ord a => Ord (Maybe a) where
+    Just x `compare` Just y = x `compare` y
+    Nothing `compare` Nothing = EQ
+    Nothing `compare` Just _  = LT
+    Just _ `compare` Nothing  = GT
hunk ./lib/jhc/Jhc/Monad.hs 2
-
hunk ./lib/jhc/Jhc/Monad.hs 14
-
hunk ./lib/jhc/Jhc/Monad.hs 20
-
hunk ./lib/jhc/Jhc/Monad.hs 70
-
-
adddir ./lib/jhc/Jhc/Type
addfile ./lib/jhc/Jhc/Type/Basic.hs
hunk ./lib/jhc/Jhc/Type/Basic.hs 1
+module Jhc.Type.Basic where
+
+import Jhc.Prim.Prim
+import Jhc.Prim
+
+data Maybe a  =  Nothing | Just a
addfile ./lib/jhc/Jhc/Type/Handle.hs
hunk ./lib/jhc/Jhc/Type/Handle.hs 1
+module Jhc.Type.Handle where
+
+import Jhc.Prim
+import Jhc.Basics
+import Jhc.Type.Ptr
+import Jhc.Type.Basic
+
+data CFile
+
+data IOMode = ReadMode | WriteMode | AppendMode | ReadWriteMode
+
+data Handle = Handle {
+    handleName :: [Char],
+    handleFile :: !(Ptr (Ptr CFile)),
+    handleBinary :: !Bool,
+    handleIsPipe :: !Bool,
+    handleIOMode :: !IOMode
+    }
+
+data IOErrorType
+    = AlreadyExists
+    | DoesNotExist
+    | AlreadyInUse
+    | Full
+    | EOF
+    | IllegalOperation
+    | Permission
+    | User
+
+data IOError = IOError {
+    ioeGetErrorType :: !IOErrorType,
+    ioeGetErrorString :: String,
+    ioeGetHandle :: Maybe Handle,
+    ioeGetFileName :: Maybe String
+    }
addfile ./lib/jhc/Jhc/Type/Ptr.hs
hunk ./lib/jhc/Jhc/Type/Ptr.hs 1
+module Jhc.Type.Ptr where
+
+import Jhc.Prim.Bits
+
+data Ptr a = Ptr BitsPtr_
+data FunPtr a = FunPtr BitsPtr_
hunk ./lib/jhc/System/C/Stdio.hs 8
+import Jhc.Type.Handle
hunk ./lib/jhc/jhc.yaml 32
-        - Jhc.Hole
hunk ./lib/jhc/jhc.yaml 33
-        - Jhc.JumpPoint
hunk ./lib/jhc/jhc.yaml 54
+        - Jhc.Type.Basic
+        - Jhc.Type.Handle
+        - Jhc.Type.Ptr
+
+#        - Jhc.Hole
+#        - Jhc.JumpPoint
hunk ./src/FrontEnd/Tc/Module.hs 181
-                        | c `elem` enumDerivableClasses, t `elem` [tc_Bool, tc_Ordering] = [f r]
+                        | c `elem` enumDerivableClasses, t `elem` [tc_Bool, tc_Ordering, tc_IOErrorType, tc_IOMode] = [f r]
hunk ./src/data/names.txt 3
+IOErrorType  Jhc.Type.Handle.IOErrorType
+IOMode  Jhc.Type.Handle.IOMode