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__)
23 --then waste time deciding whether to panic. FastBool should normally
24 --be at least as fast as Bool, one would hope...
28 isFastTrue _ = panic "FastTypes: isFastTrue"
30 -- note that fastOr and fastAnd are strict in both arguments
31 -- since they are unboxed
34 fastOr _ _ = panicFastInt "FastTypes: fastOr"
38 fastAnd _ _ = panicFastInt "FastTypes: fastAnd"
40 --these "panicFastInt"s (formerly known as "panic#") rely on
41 --FastInt = FastBool ( = Int# presumably),
42 --haha, true enough when __GLASGOW_HASKELL__. Why can't we have functions
43 --that return _|_ be kind-polymorphic ( ?? to be precise ) ?
46 --Isn't comparison to zero sometimes faster on CPUs than comparison to 1?
47 -- (since using Int# as _synonym_ fails to guarantee that it will
48 -- only take on values of 0 and 1)
52 -- note that fastOr and fastAnd are strict in both arguments
53 -- since they are unboxed
54 -- Also, to avoid incomplete-pattern warning
55 -- (and avoid wasting time with redundant runtime checks),
56 -- we don't pattern-match on both 0# and 1# .
66 #else /* ! __GLASGOW_HASKELL__ */
71 -- make sure these are as strict as the unboxed version,
72 -- so that the performance characteristics match
73 fastOr False False = False
75 fastAnd True True = True
78 #endif /* ! __GLASGOW_HASKELL__ */
80 fastBool :: Bool -> FastBool
81 isFastTrue :: FastBool -> Bool
82 fastOr :: FastBool -> FastBool -> FastBool
83 fastAnd :: FastBool -> FastBool -> FastBool