--------------------------------------------------------------------------------
--                                                                            --
-- Write class (only used for running monadic computations)                   --
--                                                                            --
--------------------------------------------------------------------------------

class Write x where
  write :: x -> IO ()

instance Write (IO ()) where
  write = id

instance Write Int where
  write = put . show

instance Write Bool where
   write = put . show

instance Write x => Write [x] where
  write xs 
    = do { put "[" ; doAllSepWith (put ",") (map write xs) ; put "]" }

-- forget the state 
 
instance Write x => Write (state,x) where
  write (_,x) = write x

--------------------------------------------------------------------------------
--                                                                            --
--  RunIO is is used to run a monadic computation                             --
--                                                                            --
--------------------------------------------------------------------------------

-- Run class

class Monad m => RunIO m x where
  runIO :: m x -> IO ()
  
instance Write (m x) => RunIO m x where
  runIO = write  
  
-- Initial (some monads need it to run)

class Initial x where
  initial :: x  
  
instance Initial Level where
  initial = 0  

--------------------------------------------------------------------------------
