<commit_before>-----------------------------------------------------------------------------
-- IO monad extensions:
--
-- Suitable for use with Hugs 98.
-----------------------------------------------------------------------------

module Hugs.IOExts
	( fixIO				-- :: (a -> IO a) -> IO a
	, unsafePerformIO		-- :: IO a -> a
	, unsafeInterleaveIO		-- :: IO a -> IO a

	, RealWorld

	, performGC

	, IOModeEx(..)	      	-- instance (Eq, Read, Show)
	, openFileEx	      	-- :: FilePath -> IOModeEx -> IO Handle

	, unsafePtrEq
	, unsafePtrToInt
	, unsafeCoerce
	
	  -- backward compatibility with IOExtensions
	, readBinaryFile        -- :: FilePath -> IO String
	, writeBinaryFile       -- :: FilePath -> String -> IO ()
	, appendBinaryFile      -- :: FilePath -> String -> IO ()
	, openBinaryFile        -- :: FilePath -> IOMode -> IO Handle

	   -- non-echoing getchar
	, getCh                 -- :: IO Char
	, argv                  -- :: [String]
	) where

import Hugs.Prelude
import Hugs.IO( IOMode(..), Handle, openFile )
import Hugs.System ( getArgs )

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

data RealWorld = RealWorld

primitive performGC "primGC" :: IO ()

unsafePerformIO :: IO a -> a
unsafePerformIO m = valueOf (basicIORun m)

unsafeInterleaveIO :: IO a -> IO a
unsafeInterleaveIO m = return (unsafePerformIO m)

primitive unsafePtrEq    :: a -> a -> Bool
primitive unsafePtrToInt :: a -> Int

fixIO :: (a -> IO a) -> IO a
fixIO m = IO (\ s -> r `seq` s a)
   where
    r = basicIORun (m a)
    a = valueOf r

primitive unsafeCoerce "primUnsafeCoerce" :: a -> b<commit_msg>Change fixIO so that concurrency primitives can be used within its argument.  (It used to use a private thread pool.)<commit_after>-----------------------------------------------------------------------------
-- IO monad extensions:
--
-- Suitable for use with Hugs 98.
-----------------------------------------------------------------------------

module Hugs.IOExts
	( fixIO				-- :: (a -> IO a) -> IO a
	, unsafePerformIO		-- :: IO a -> a
	, unsafeInterleaveIO		-- :: IO a -> IO a

	, RealWorld

	, performGC

	, IOModeEx(..)	      	-- instance (Eq, Read, Show)
	, openFileEx	      	-- :: FilePath -> IOModeEx -> IO Handle

	, unsafePtrEq
	, unsafePtrToInt
	, unsafeCoerce
	
	  -- backward compatibility with IOExtensions
	, readBinaryFile        -- :: FilePath -> IO String
	, writeBinaryFile       -- :: FilePath -> String -> IO ()
	, appendBinaryFile      -- :: FilePath -> String -> IO ()
	, openBinaryFile        -- :: FilePath -> IOMode -> IO Handle

	   -- non-echoing getchar
	, getCh                 -- :: IO Char
	, argv                  -- :: [String]
	) where

import Hugs.Prelude
import Hugs.IO( IOMode(..), Handle, openFile )
import Hugs.IORef
import Hugs.System ( getArgs )

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

data RealWorld = RealWorld

primitive performGC "primGC" :: IO ()

unsafePerformIO :: IO a -> a
unsafePerformIO m = valueOf (basicIORun m)

unsafeInterleaveIO :: IO a -> IO a
unsafeInterleaveIO m = return (unsafePerformIO m)

primitive unsafePtrEq    :: a -> a -> Bool
primitive unsafePtrToInt :: a -> Int

fixIO :: (a -> IO a) -> IO a
fixIO f = do
	r <- newIORef (throw NonTermination)
	x <- f (unsafePerformIO (readIORef r))
	writeIORef r x
	return x

primitive unsafeCoerce "primUnsafeCoerce" :: a -> b
{'fraction_non_alphanumeric': 0.2475742428697442, 'fraction_numerical': 0.0011761246692149367, 'mean_word_length': 1.554054054054054, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1040238', 'n_tokens_mistral': 1040, 'n_tokens_neox': 990, 'n_words': 307}