2 % (c) The University of Glasgow, 2000-2006
4 \section{Fast booleans}
8 --fastBool could be called bBox; isFastTrue, bUnbox; but they're not
9 FastBool, fastBool, isFastTrue, fastOr, fastAnd
12 #if defined(__GLASGOW_HASKELL__)
25 --then waste time deciding whether to panic. FastBool should normally
26 --be at least as fast as Bool, one would hope...
30 isFastTrue _ = panic "FastTypes: isFastTrue"
32 -- note that fastOr and fastAnd are strict in both arguments
33 -- since they are unboxed
36 fastOr _ _ = panicFastInt "FastTypes: fastOr"
40 fastAnd _ _ = panicFastInt "FastTypes: fastAnd"
42 --these "panicFastInt"s (formerly known as "panic#") rely on
43 --FastInt = FastBool ( = Int# presumably),
44 --haha, true enough when __GLASGOW_HASKELL__. Why can't we have functions
45 --that return _|_ be kind-polymorphic ( ?? to be precise ) ?
48 --Isn't comparison to zero sometimes faster on CPUs than comparison to 1?
49 -- (since using Int# as _synonym_ fails to guarantee that it will
50 -- only take on values of 0 and 1)
54 -- note that fastOr and fastAnd are strict in both arguments
55 -- since they are unboxed
56 -- Also, to avoid incomplete-pattern warning
57 -- (and avoid wasting time with redundant runtime checks),
58 -- we don't pattern-match on both 0# and 1# .
68 #else /* ! __GLASGOW_HASKELL__ */
73 -- make sure these are as strict as the unboxed version,
74 -- so that the performance characteristics match
75 fastOr False False = False
77 fastAnd True True = True
80 #endif /* ! __GLASGOW_HASKELL__ */
82 fastBool :: Bool -> FastBool
83 isFastTrue :: FastBool -> Bool
84 fastOr :: FastBool -> FastBool -> FastBool
85 fastAnd :: FastBool -> FastBool -> FastBool