home *** CD-ROM | disk | FTP | other *** search
/ PSION CD 2 / PsionCDVol2.iso / Programs / 876 / hugs.sis / System.hs < prev    next >
Encoding:
Text File  |  2000-09-21  |  1.7 KB  |  53 lines

  1. -----------------------------------------------------------------------------
  2. -- Standard Library: System operations
  3. --
  4. -- Warning: the implementation of these functions in Hugs 98 is very weak.
  5. -- The functions themselves are best suited to uses in compiled programs,
  6. -- and not to use in an interpreter-based environment like Hugs.
  7. --
  8. -- Suitable for use with Hugs 98
  9. -----------------------------------------------------------------------------
  10.  
  11. module System (
  12.     ExitCode(..), exitWith, exitFailure,
  13.     getArgs, getProgName, getEnv, 
  14.     system
  15.     ) where
  16.  
  17. data ExitCode = ExitSuccess | ExitFailure Int
  18.                 deriving (Eq, Ord, Read, Show)
  19.  
  20. primitive primArgc          :: IO Int
  21. primitive primArgv          :: Int -> IO String
  22.  
  23. getArgs                     :: IO [String]
  24. getArgs                      = do argc <- primArgc
  25.                                  mapM primArgv [1..argc-1]
  26.  
  27. getProgName                 :: IO String
  28. getProgName                  = primArgv 0
  29.  
  30. primitive getEnv            :: String -> IO String
  31.  
  32. system                      :: String -> IO ExitCode
  33. system s                     = do r <- primSystem s
  34.                                   return (toExitCode r)
  35.  
  36. exitWith                    :: ExitCode -> IO a
  37. exitWith c                   = primExitWith (fromExitCode c)
  38.  
  39. exitFailure            :: IO a
  40. exitFailure             = exitWith (ExitFailure 1)
  41.  
  42. primitive primSystem        :: String -> IO Int
  43.  
  44. toExitCode                  :: Int -> ExitCode
  45. toExitCode 0                 = ExitSuccess
  46. toExitCode n                 = ExitFailure n
  47.  
  48. fromExitCode                :: ExitCode -> Int
  49. fromExitCode ExitSuccess     = 0
  50. fromExitCode (ExitFailure n) = n
  51.  
  52. -----------------------------------------------------------------------------
  53.