[project @ 2003-04-25 17:43:06 by ross]
[ghc-base.git] / GHC / Base.lhs
index 7ee7d7d..0935b5c 100644 (file)
@@ -399,10 +399,10 @@ not                       :: Bool -> Bool
 not True               =  False
 not False              =  True
 
--- |'otherwise' is defined as the value 'True'; it helps to make
+-- |'otherwise' is defined as the value 'True'.  It helps to make
 -- guards more readable.  eg.
 --
--- >  f x | x \< 0     = ...
+-- >  f x | x < 0     = ...
 -- >      | otherwise = ...
 otherwise              :: Bool
 otherwise              =  True
@@ -595,14 +595,13 @@ id x                      =  x
 lazy :: a -> a
 lazy x = x
 
---     SLPJ: this was transferred from the TH branch
---     and I've forgotten what it was for... so I'll
---     comment it back out for now.  It conflicts with
---     'assert' in GHC.Prim
 -- Assertion function. This simply ignores its boolean argument.
 -- The compiler may rewrite it to (assertError line)
--- assert :: Bool -> a -> a
--- assert pred r = r
+--     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
  
 -- constant function
 const                  :: a -> b -> a
@@ -668,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}
 
 %*********************************************************
 %*                                                     *