Skip to content

Commit fc8371c

Browse files
authored
Merge pull request #30 from aspiwack/haddock-for-first-release
Prepare for release
2 parents 091e3b1 + 8788153 commit fc8371c

File tree

15 files changed

+176
-114
lines changed

15 files changed

+176
-114
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: arnaud@spiwack.net
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: 26 additions & 17 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
@@ -22,19 +35,13 @@ katipNamespace = unsafePerformIO Benign.newField
2235

2336
-- | See 'Katip.katipAddContext'.
2437
withKatipContext :: (Katip.LogItem i) => i -> Benign.Strat a -> a -> a
25-
withKatipContext item = Benign.withAltering katipContext addContext
26-
where
27-
addContext (Just st) = Just $ st <> Katip.liftPayload item
28-
addContext Nothing = error "todo"
38+
withKatipContext item = Benign.withAltering katipContext (<> Just (Katip.liftPayload item))
2939

3040
-- | See 'Katip.katipAddNamespace'.
3141
withKatipNamespace :: Katip.Namespace -> Benign.Strat a -> a -> a
32-
withKatipNamespace namespace = Benign.withAltering katipNamespace addNamespace
33-
where
34-
addNamespace (Just st) = Just $ st <> namespace
35-
addNamespace Nothing = error "todo"
42+
withKatipNamespace namespace = Benign.withAltering katipNamespace (<> Just namespace)
3643

37-
-- | Within this computation, Katip is configured.
44+
-- | Within this computation, Katip is configured for pure code.
3845
withKatip ::
3946
(Katip.LogItem c) =>
4047
Katip.LogEnv ->
@@ -48,7 +55,9 @@ withKatip env ctx namespace strat =
4855
. Benign.withSettingIO' katipContext (Katip.liftPayload ctx)
4956
. Benign.withSettingIO katipNamespace namespace strat
5057

51-
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
5261
logLocM severity str = withFrozenCallStack spanLog
5362
where
5463
-- The whole purpose of naming `span` is to freeze the call stack. It's
@@ -59,16 +68,16 @@ logLocM severity str = withFrozenCallStack spanLog
5968
-- scratch. This would be invisible. I tried to harden this function by
6069
-- declaring type signatures everywhere. I haven't tested it yet though. It
6170
-- may be wrong.
62-
spanLog :: HasCallStack => Benign.Strat a -> a -> a
63-
spanLog = Benign.unsafeSpanBenign doLog (return ())
71+
spanLog :: (HasCallStack) => a -> a
72+
spanLog = Benign.unsafeSpanBenign doLog (return ()) Benign.whnf
6473

65-
doLog :: HasCallStack => IO ()
74+
doLog :: (HasCallStack) => IO ()
6675
doLog = do
6776
-- Making an intermediary `KatipContextT` is a little roundabout, but it's
6877
-- easier than reaching to Katip's internals.
6978
--
7079
-- TODO: catch errors
71-
Just env <- Benign.lookupLocalState katipEnv
72-
Just ctx <- Benign.lookupLocalState katipContext
73-
Just namespace <- Benign.lookupLocalState katipNamespace
80+
Just env <- Benign.lookupLexicalState katipEnv
81+
Just ctx <- Benign.lookupLexicalState katipContext
82+
Just namespace <- Benign.lookupLexicalState katipNamespace
7483
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: arnaud@spiwack.net
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
------------------------------------------------------------------------------

nix/sources.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
"homepage": "https://github.com/NixOS/nixpkgs",
66
"owner": "NixOS",
77
"repo": "nixpkgs",
8-
"rev": "7f9be6a505a31f88499c5d20d11f98accf5ae6ba",
9-
"sha256": "147wp515k1x08blm3nn2z994wbdnbl0vhp472ym1habfihfr7x65",
8+
"rev": "2e1496bf8652ff4af4e4d4737277f71e4a4f5cb2",
9+
"sha256": "0afb9y45zp2ikbzpbicy72l4dh9n0mgank8kqmyqxb8ib7s6qmsx",
1010
"type": "tarball",
11-
"url": "https://github.com/NixOS/nixpkgs/archive/7f9be6a505a31f88499c5d20d11f98accf5ae6ba.tar.gz",
11+
"url": "https://github.com/NixOS/nixpkgs/archive/2e1496bf8652ff4af4e4d4737277f71e4a4f5cb2.tar.gz",
1212
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
1313
}
1414
}

package.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ maintainer: arnaud@spiwack.net
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)