我打开了GHC/Num.lhs
文件,可以找到以下代码:
instance Num Int where
I# x + I# y = I# (x +# y)
I# x - I# y = I# (x -# y)
negate (I# x) = I# (negateInt# x)
I# x * I# y = I# (x *# y)
abs n = if n `geInt` 0 then n else negate n
signum n | n `ltInt` 0 = negate 1
| n `eqInt` 0 = 0
| otherwise = 1
{-# INLINE fromInteger #-} -- Just to be sure!
fromInteger i = I# (integerToInt i)
它们是GHC实施的某种内在运营商吗?
答案 0 :(得分:1)
它们是GHC primops,即在Haskell中未实现但由运行时提供的基本操作。
这些特定的declared in GHC.Prim
并实施unboxed Int
s:Int#
是未装箱Int
的类型,I#
是Int
的构造函数}(即data Int = I# Int#
),+#
为Int#
添加。