From 74ed71ccbe01ac91ce32c69451a637df344db53e Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Wed, 27 Jan 2010 19:25:13 -0500 Subject: [PATCH] floating: Use a strict data constructor for FEnv. This seems a bit more natural than using seq in the definition of pure. --- Data/Floating/Environment.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Data/Floating/Environment.hs b/Data/Floating/Environment.hs index bfdf945..ae6ec7b 100644 --- a/Data/Floating/Environment.hs +++ b/Data/Floating/Environment.hs @@ -94,9 +94,12 @@ instance Storable FEnvState where -- | Container for computations which will be run in a modified floating point -- environment. The FEnv container records all operations for later evaluation --- by 'fenvEval'. Do not use the 'Eq' or 'Show' instances, they are provided --- only because Num requires them. -data FEnv a = forall b . FEnv (b -> a) b +-- by 'fenvEval'. Note that 'pure' is strict in order to force evaluation +-- of floating point values stored in the container. +-- +-- Do not use the 'Eq' or 'Show' instances, they are provided only because Num +-- requires them. +data FEnv a = forall b . FEnv (b -> a) !b -- In the following instances, the two FEnv parts must be bashed together -- exactly once every time the contained value is extracted. Care must be @@ -108,7 +111,7 @@ instance Functor FEnv where fmap f (FEnv g x) = FEnv (f . g) x instance Applicative FEnv where - pure x = seq x (FEnv id x) + pure = FEnv id (FEnv f x) <*> (FEnv g y) = FEnv (\(x',y') -> f x' . g $ y') (x, y) -- For hysterical raisins, we need to instance Eq and Show since they are -- 2.11.4.GIT