Hi, I'm extract this fragment of code from my tesis program. I'm try to reduce more, but i can't. The concrete question is: What does {_Gc Black Hole} mean? ======================================================= ===== Concrete problem here, implementation later ===== ======================================================= I'm execute mainOk and receive the expected result Main> mainOk Dyn Hello World!! (82 reductions, 196 cells) I'm execute main and system stop, not reduction executed (27 reductions in five minutes of wait) Main> main {Interrupted!} (27 reductions, 64 cells) I'm expected Dyn <Hello World !!> I'm break and re run and receive the message Main> main Program error: {_Gc Black Hole} (8 reductions, 51 cells) What does _Gc Black Hole mean? ======================================================= ========== Implementation can look here =============== ======================================================= Tested on Hugs 98 February 2001 in Windows 98 with options -98 +som ======================================================= ================ Class Result ========================= =======================================================
class Result r where toString :: r -> String fromString :: String -> r toR :: Result r' => r -> r' fromR :: Result r' => r'-> r
======================================================= ============ Class SubResult ========================== =======================================================
class Result a => SubResult a where toHtml :: a -> Html fromHtml :: Html -> a
======================================================= ========= Html data type ============================== =======================================================
newtype Html = Html String deriving Show
======================================================= ========= Html are Result and SubResult =============== =======================================================
instance Result Html where toString (Html st) = st fromString st = Html ("<" ++ st ++ ">") toR (Html st) = toR st fromR r = toR r
instance SubResult Html where toHtml = id fromHtml = id
======================================================= =========== Dyn data type ============================= =======================================================
data Dyn = forall a . SubResult a => Dyn a
instance Show Dyn where show (Dyn x) = "Dyn " ++ toString x
======================================================= =========== Dyn are Result and SubResult ============== =======================================================
instance Result Dyn where toString (Dyn x) = toString x fromString st = Dyn st fromR = toR toR (Dyn x) = toR x
instance SubResult Dyn where toHtml (Dyn x) = toHtml x fromHtml html = Dyn html
======================================================= ============ String are Result and SubResult ========== =======================================================
instance Result String where toString = id fromString = id fromR = toString toR = fromString
instance SubResult String where toHtml st = fromString st fromHtml html = toString html
======================================================= =============== Rule Class ============================ =======================================================
class (Result r) => Rule e r where apply :: e r -> r -> r rws :: (Result r') => (r -> r') -> e r
======================================================= =============== SubRule Class ========================= =======================================================
class (Rule e r, SubResult r) => SubRule e r where rwsS :: (SubResult r') => (r -> r') -> e r
======================================================= ======== TRule data type ============================== =======================================================
newtype TRule r = TRule (r -> r)
======================================================= ========= TRule are Rule ============================== =======================================================
instance Result a => Rule TRule a where apply (TRule f) r = f r rws f = TRule (\r -> toR (f r))
======================================================= =========TRule are SubRule ============================ =======================================================
instance SubResult a => SubRule TRule a where rwsS f = TRule (\r -> toR $ toHtml (f r))
======================================================= ========== Examples =================================== =======================================================
genRule1 :: Rule e r => e r genRule1 = rws (\r -> toR r ++ "!!")
genRule2 :: SubRule e r => e r genRule2 = rwsS (\r -> toR r ++ "!!")
mainOk:: Dyn mainOk = apply (genRule1::TRule Dyn) (toR "Hello World")
main :: Dyn main = apply (genRule2::TRule Dyn) (toR "Hello World")
======================================================== ===================== The end ========================== ======================================================== Saludos Pablo "Yeti" Cardenal from La Plata, Buenos Aires, Argentina
The concrete question is: What does {_Gc Black Hole} mean?
A black hole is a particular kind of cyclic definition such as: let a = a+1 in a where the value of an expression depends on the value of that same expression. They are a special kind of infinite loop which, it turns out, a garbage collector is able to detect. When the GC detects such loops, it overwrites the thunk with the _Gc Black Hole value and Hugs can report an error instead of just grinding forever. For that to happen, the GC must run - obviously your example doesn't allocate (or use stack space) each time round the loop or does so very, very slowly so it doesn't get detected. But then you hit ctrl-C and Hugs runs the garbage collector (and detects the loop) before evaluating the next command and so Hugs detects the error on the second evaluation. Hmmm, I can see why the error message puzzled you - perhaps we should change the message? {Infinite Loop} is the best I can come up with. -- Alastair Reid
At 16:40 -0600 2001/04/11, Alastair Reid wrote:
The concrete question is: What does {_Gc Black Hole} mean?
A black hole is a particular kind of cyclic definition ... a special kind of infinite loop which, it turns out, a garbage collector is able to detect. ... Hmmm, I can see why the error message puzzled you - perhaps we should change the message? {Infinite Loop} is the best I can come up with.
Perhaps {GC detected infinite loop}. Hans Aberg * Email: Hans Aberg <mailto:haberg@member.ams.org> * Home Page: <http://www.matematik.su.se/~haberg/> * AMS member listing: <http://www.ams.org/cml/>
participants (3)
-
Alastair Reid -
Hans Aberg -
pablocardenal@laplatavive.com