Skip to content

Commit 8788153

Browse files
committed
A big pass on documentation and interface preparing for release
Closes #14
1 parent 3806f71 commit 8788153

File tree

11 files changed

+164
-96
lines changed

11 files changed

+164
-96
lines changed

backends/katip/benign-katip.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
cabal-version: 1.12
22

3-
-- This file has been generated from package.yaml by hpack version 0.35.0.
3+
-- This file has been generated from package.yaml by hpack version 0.38.0.
44
--
55
-- see: https://github.com/sol/hpack
66

77
name: benign-katip
88
version: 0.1.0
9-
synopsis: A library for benign effects
9+
synopsis: A Benign backend for the Katip library
1010
description: see README.md.
1111
homepage: https://github.com/aspiwack/haskell-benign#readme
1212
bug-reports: https://github.com/aspiwack/haskell-benign/issues

backends/katip/package.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ author: Arnaud Spiwack
44
maintainer: [email protected]
55
github: aspiwack/haskell-benign
66
copyright: MIT
7-
synopsis: A library for benign effects
7+
synopsis: A Benign backend for the Katip library
88
description: see README.md.
99

1010
dependencies:

backends/katip/src/Benign/Katip.hs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
{-# LANGUAGE GHC2021 #-}
22

3-
module Benign.Katip where
3+
-- | This module is a small wrapper around
4+
-- [Katip](https://hackage.haskell.org/package/katip) to allow logging in pure
5+
-- code.
6+
--
7+
-- The wrapper is a little primitive still and you will have to handle the
8+
-- transition from IO code to pure code manually. Pull requests are, of course,
9+
-- welcome.
10+
module Benign.Katip
11+
( withKatipContext,
12+
withKatipNamespace,
13+
withKatip,
14+
logLocM,
15+
)
16+
where
417

518
import Benign qualified
619
import GHC.Stack
@@ -28,7 +41,7 @@ withKatipContext item = Benign.withAltering katipContext (<> Just (Katip.liftPay
2841
withKatipNamespace :: Katip.Namespace -> Benign.Strat a -> a -> a
2942
withKatipNamespace namespace = Benign.withAltering katipNamespace (<> Just namespace)
3043

31-
-- | Within this computation, Katip is configured.
44+
-- | Within this computation, Katip is configured for pure code.
3245
withKatip ::
3346
(Katip.LogItem c) =>
3447
Katip.LogEnv ->
@@ -42,7 +55,9 @@ withKatip env ctx namespace strat =
4255
. Benign.withSettingIO' katipContext (Katip.liftPayload ctx)
4356
. Benign.withSettingIO katipNamespace namespace strat
4457

45-
logLocM :: forall a. (HasCallStack) => Katip.Severity -> Katip.LogStr -> Benign.Strat a -> a -> a
58+
-- | @'logLocM' s msg a@ logs a an event, like Katip's 'Katip.logLocM', before
59+
-- evaluating @a@.
60+
logLocM :: forall a. (HasCallStack) => Katip.Severity -> Katip.LogStr -> a -> a
4661
logLocM severity str = withFrozenCallStack spanLog
4762
where
4863
-- The whole purpose of naming `span` is to freeze the call stack. It's
@@ -53,16 +68,16 @@ logLocM severity str = withFrozenCallStack spanLog
5368
-- scratch. This would be invisible. I tried to harden this function by
5469
-- declaring type signatures everywhere. I haven't tested it yet though. It
5570
-- may be wrong.
56-
spanLog :: HasCallStack => Benign.Strat a -> a -> a
57-
spanLog = Benign.unsafeSpanBenign doLog (return ())
71+
spanLog :: (HasCallStack) => a -> a
72+
spanLog = Benign.unsafeSpanBenign doLog (return ()) Benign.whnf
5873

59-
doLog :: HasCallStack => IO ()
74+
doLog :: (HasCallStack) => IO ()
6075
doLog = do
6176
-- Making an intermediary `KatipContextT` is a little roundabout, but it's
6277
-- easier than reaching to Katip's internals.
6378
--
6479
-- TODO: catch errors
65-
Just env <- Benign.lookupLocalState katipEnv
66-
Just ctx <- Benign.lookupLocalState katipContext
67-
Just namespace <- Benign.lookupLocalState katipNamespace
80+
Just env <- Benign.lookupLexicalState katipEnv
81+
Just ctx <- Benign.lookupLexicalState katipContext
82+
Just namespace <- Benign.lookupLexicalState katipNamespace
6883
Katip.runKatipContextT env ctx namespace $ Katip.logLocM severity str

backends/timestats/benign-timestats.cabal

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
cabal-version: 1.12
22

3-
-- This file has been generated from package.yaml by hpack version 0.35.0.
3+
-- This file has been generated from package.yaml by hpack version 0.38.0.
44
--
55
-- see: https://github.com/sol/hpack
66

77
name: benign-timestats
88
version: 0.1.0
9-
synopsis: A library for benign effects
10-
description: see README.md.
9+
synopsis: A Benign backend for the Timestats library
10+
description: See the Benign library.
1111
homepage: https://github.com/aspiwack/haskell-benign#readme
1212
bug-reports: https://github.com/aspiwack/haskell-benign/issues
1313
author: Arnaud Spiwack

backends/timestats/package.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ author: Arnaud Spiwack
44
maintainer: [email protected]
55
github: aspiwack/haskell-benign
66
copyright: MIT
7-
synopsis: A library for benign effects
8-
description: see README.md.
7+
synopsis: A Benign backend for the Timestats library
8+
description: See the Benign library.
99

1010
dependencies:
1111
- base

backends/timestats/src/Benign/TimeStats.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import Control.Exception
77
import Debug.TimeStats qualified as TimeStats
88
import System.IO.Unsafe (unsafePerformIO)
99

10+
-- | @'measure' label strat thing@ measures, in the style of
11+
-- 'TimeStats.measurePure', of running @strat thing@.
1012
measure :: String -> Benign.Strat a -> a -> a
1113
measure label strat thing = unsafePerformIO $ TimeStats.measureM label $ do Benign.E <- evaluate (strat thing); return thing
1214
{-# NOINLINE measure #-}

benign.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
cabal-version: 1.12
22

3-
-- This file has been generated from package.yaml by hpack version 0.35.0.
3+
-- This file has been generated from package.yaml by hpack version 0.38.0.
44
--
55
-- see: https://github.com/sol/hpack
66

77
name: benign
88
version: 0.1.0
99
synopsis: A library for benign effects
10-
description: see README.md.
10+
description: See the Benign library.
1111
homepage: https://github.com/aspiwack/haskell-benign#readme
1212
bug-reports: https://github.com/aspiwack/haskell-benign/issues
1313
author: Arnaud Spiwack

examples/SimplePrint.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ log log_line = Benign.unsafeSpanBenign do_log (return ())
4242
where
4343
do_log :: IO ()
4444
do_log = do
45-
ctx <- Benign.lookupLocalState context
45+
ctx <- Benign.lookupLexicalState context
4646
putStrLn (fromMaybe "" ctx ++ " " ++ log_line)
4747

4848
------------------------------------------------------------------------------

package.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ maintainer: [email protected]
55
github: aspiwack/haskell-benign
66
copyright: MIT
77
synopsis: A library for benign effects
8-
description: see README.md.
8+
description: See the Benign library.
99

1010
dependencies:
1111
- base

0 commit comments

Comments
 (0)