# Changeset View

Changeset View

# Standalone View

Standalone View

# libraries/base/GHC/Base.hs

Show First 20 Lines • Show All 977 Lines • ▼ Show 20 Line(s) | |||||

978 | f $ x = f x | 978 | f $ x = f x | ||

979 | 979 | | |||

980 | -- | Strict (call-by-value) application, defined in terms of 'seq'. | 980 | -- | Strict (call-by-value) application, defined in terms of 'seq'. | ||

981 | ($!) :: (a -> b) -> a -> b | 981 | ($!) :: (a -> b) -> a -> b | ||

982 | f $! x = let !vx = x in f vx -- see #2273 | 982 | f $! x = let !vx = x in f vx -- see #2273 | ||

983 | 983 | | |||

984 | -- | @'until' p f@ yields the result of applying @f@ until @p@ holds. | 984 | -- | @'until' p f@ yields the result of applying @f@ until @p@ holds. | ||

985 | until :: (a -> Bool) -> (a -> a) -> a -> a | 985 | until :: (a -> Bool) -> (a -> a) -> a -> a | ||

986 | until p f = go | 986 | until p f = \ !x -> go x | ||

987 | where | 987 | where | ||

988 | go x | p x = x | 988 | go x | p x = x | ||

989 | | otherwise = go (f x) | 989 | | otherwise = go (f x) | ||

990 | -- In the Prelude definition, x is not forced explicitly. However, until is | ||||

991 | -- actually strict in x. We therefore force x explicitly for two reasons: 1. | ||||

992 | -- There is some chance that it will turn an undetectable infinite loop into a | ||||

993 | -- useful exception, and 2. It makes strictness analysis slightly more precise, | ||||

994 | -- which can't be a bad thing. We force x upon entering until, instead of go, | ||||

995 | -- because although the latter gives better strictness analysis, it also risks | ||||

996 | -- forcing it twice on each iteration, which would slow things down. | ||||

990 | 997 | | |||

991 | -- | 'asTypeOf' is a type-restricted version of 'const'. It is usually | 998 | -- | 'asTypeOf' is a type-restricted version of 'const'. It is usually | ||

992 | -- used as an infix operator, and its typing forces its first argument | 999 | -- used as an infix operator, and its typing forces its first argument | ||

993 | -- (which is usually overloaded) to have the same type as the second. | 1000 | -- (which is usually overloaded) to have the same type as the second. | ||

994 | asTypeOf :: a -> a -> a | 1001 | asTypeOf :: a -> a -> a | ||

995 | asTypeOf = const | 1002 | asTypeOf = const | ||

996 | 1003 | | |||

997 | ---------------------------------------------- | 1004 | ---------------------------------------------- | ||

▲ Show 20 Lines • Show All 146 Lines • Show Last 20 Lines |