isevaluated (empty) → 0.1
raw patch · 3 files changed
+42/−0 lines, 3 filesdep +basedep +ghcsetup-changed
Dependencies added: base, ghc
Files
- Data/IsEvaluated.hs +21/−0
- Setup.lhs +3/−0
- isevaluated.cabal +18/−0
+ Data/IsEvaluated.hs view
@@ -0,0 +1,21 @@+module Data.IsEvaluated(isEvaluated) where++import RtClosureInspect++-- |Checks whether Control.Exception.evaluate (or rwhnf) would do no work+-- when applied to the value. May produce false negatives (where isEvaluated+-- thinks it would, but it actually wouldn't) in some cases.+--+-- Use case: if isEvaluated foo returns True, then evaluate foo will never+-- throw an exception, or indeed take more than constant (small) time.+isEvaluated :: a -> IO Bool+isEvaluated a = (discriminate . tipe) `fmap` getClosureData a+ where+ discriminate Constr = True+ discriminate Fun = True+ discriminate (Indirection _) = True+ discriminate (MutVar _) = True+ discriminate (MVar _) = True+ discriminate PAP = True+ -- It might be possible to handle THUNK_SELECTOR specially+ discriminate _ = False
+ Setup.lhs view
@@ -0,0 +1,3 @@+#!/usr/bin/env runhaskell+> import Distribution.Simple+> main = defaultMain
+ isevaluated.cabal view
@@ -0,0 +1,18 @@+name: isevaluated+version: 0.1+synopsis: Check whether a value has been evaluated+description: An IO action to check whether some value has been evaluated.+ .+ If isEvaluated returns True, evaluating it to weak-head+ normal form won't throw exceptions or take time.+category: Control, Data+license: PublicDomain+author: Svein Ove Aas+maintainer: svein.ove@aas.no+build-type: Simple+cabal-version: >= 1.2+stability: experimental++Library+ build-depends: base, ghc > 6.10.1, ghc <= 6.10.3+ Exposed-Modules: Data.IsEvaluated