X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=GHC%2FBase.lhs;h=2598583cbca667699d08a15c35353a479a8c5f91;hb=9da2d4c92821be09b27afa5b8bc1368b305a1496;hp=e3bc34665f08e14f2d33d389e094cdc1f1cb408b;hpb=c83f5ad9dbc5859bec565e4a6593c8cb105b5b64;p=ghc-base.git diff --git a/GHC/Base.lhs b/GHC/Base.lhs index e3bc346..2598583 100644 --- a/GHC/Base.lhs +++ b/GHC/Base.lhs @@ -597,6 +597,9 @@ lazy x = x -- Assertion function. This simply ignores its boolean argument. -- The compiler may rewrite it to (assertError line) +-- SLPJ: in 5.04 etc 'assert' is in GHC.Prim, +-- but from Template Haskell onwards it's simply +-- defined here in Base.lhs assert :: Bool -> a -> a assert pred r = r @@ -664,6 +667,29 @@ data (:*:) a b = a :*: b #endif \end{code} +%********************************************************* +%* * +\subsection{@getTag@} +%* * +%********************************************************* + +Returns the 'tag' of a constructor application; this function is used +by the deriving code for Eq, Ord and Enum. + +The primitive dataToTag# requires an evaluated constructor application +as its argument, so we provide getTag as a wrapper that performs the +evaluation before calling dataToTag#. We could have dataToTag# +evaluate its argument, but we prefer to do it this way because (a) +dataToTag# can be an inline primop if it doesn't need to do any +evaluation, and (b) we want to expose the evaluation to the +simplifier, because it might be possible to eliminate the evaluation +in the case when the argument is already known to be evaluated. + +\begin{code} +{-# INLINE getTag #-} +getTag :: a -> Int# +getTag x = x `seq` dataToTag# x +\end{code} %********************************************************* %* *