真实世界#在哪里定义?
Where is the realWorld# defined?
在unsafeDupablePerformIO
的定义中(当然source, docs) I found a reference to the one and only realWorld#
. So I wondered where all these functions or values that end with a #
are defined? I already found the GHC primops:它们包括seq#
、catch#
、retry#
,以及其他各种有趣的函数。它还包含一个RealWorld
类型。但是primops似乎不包含实际值realWorld#
。
{-# NOINLINE unsafeDupablePerformIO #-}
-- See Note [unsafeDupablePerformIO is NOINLINE]
unsafeDupablePerformIO :: IO a -> a
unsafeDupablePerformIO (IO m) = lazy (case m realWorld# of (# _, r #) -> r)
-- See Note [unsafeDupablePerformIO has a lazy RHS]
(请不要混用 RealWorld
和 realWorld#
:第一个是类型,第二个是值。)
GHC 中还有其他未记录的 primops 吗?或者也许所有这些都记录在某个地方,我只是还没有找到它?我可以在 GHC 源代码的哪个位置查看这些东西的实现?
realWorld#
是类型 State# RealWorld
的值,它是作为对 "the real world" 的引用的标记。 (有趣的是,它的大小为 0,并且不占用堆栈或堆上的任何 space。)
一些背景信息。 State# RealWorld
值表示程序的整个外部运行时状态。 "real world",可以说是。程序中的 main
值接收一个 State# RealWorld
值,该值通过构成它的 IO
操作进行线程化。 realWorld#
是计算 unsafeDupablePerformIO
值时的值。
至于它的定义,它是 here,不管它对你有什么好处。 :)
在unsafeDupablePerformIO
的定义中(当然source, docs) I found a reference to the one and only realWorld#
. So I wondered where all these functions or values that end with a #
are defined? I already found the GHC primops:它们包括seq#
、catch#
、retry#
,以及其他各种有趣的函数。它还包含一个RealWorld
类型。但是primops似乎不包含实际值realWorld#
。
{-# NOINLINE unsafeDupablePerformIO #-}
-- See Note [unsafeDupablePerformIO is NOINLINE]
unsafeDupablePerformIO :: IO a -> a
unsafeDupablePerformIO (IO m) = lazy (case m realWorld# of (# _, r #) -> r)
-- See Note [unsafeDupablePerformIO has a lazy RHS]
(请不要混用 RealWorld
和 realWorld#
:第一个是类型,第二个是值。)
GHC 中还有其他未记录的 primops 吗?或者也许所有这些都记录在某个地方,我只是还没有找到它?我可以在 GHC 源代码的哪个位置查看这些东西的实现?
realWorld#
是类型 State# RealWorld
的值,它是作为对 "the real world" 的引用的标记。 (有趣的是,它的大小为 0,并且不占用堆栈或堆上的任何 space。)
一些背景信息。 State# RealWorld
值表示程序的整个外部运行时状态。 "real world",可以说是。程序中的 main
值接收一个 State# RealWorld
值,该值通过构成它的 IO
操作进行线程化。 realWorld#
是计算 unsafeDupablePerformIO
值时的值。
至于它的定义,它是 here,不管它对你有什么好处。 :)