[project @ 2003-01-24 14:04:41 by simonmar]
[ghc-base.git] / GHC / Base.lhs
index fe42991..9cdd755 100644 (file)
@@ -667,6 +667,28 @@ 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 x = x `seq` dataToTag# x
+\end{code}
 
 %*********************************************************
 %*                                                     *