在GHC.Num模块中,像#和+#这样的运营商意味着什么?

时间:2016-05-11 22:40:53

标签: haskell ghc

我打开了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实施的某种内在运营商吗?

1 个答案:

答案 0 :(得分:1)

它们是GHC primops,即在Haskell中未实现但由运行时提供的基本操作。

这些特定的declared in GHC.Prim并实施unboxed IntsInt#是未装箱Int的类型,I#Int的构造函数}(即data Int = I# Int#),+#Int#添加。