-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from well-typed/edsko/demo
Demo and prepare for release
- Loading branch information
Showing
20 changed files
with
733 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
dist-newstyle/ | ||
.envrc | ||
niio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# Revision history for non-interleaved-logging | ||
# Revision history for debuggable | ||
|
||
## 0.1.0 -- YYYY-mm-dd | ||
## 0.1.0 -- 2024-11-23 | ||
|
||
* First version. Released on an unsuspecting world. | ||
* First public release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
packages: . | ||
|
||
package debuggable | ||
tests: True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
packages: . | ||
|
||
package debuggable | ||
tests: True | ||
ghc-options: -Werror |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
module Cmdline ( | ||
Cmdline(..) | ||
, Demo(..) | ||
, getCmdline | ||
) where | ||
|
||
import Options.Applicative | ||
|
||
import Demo.Invocation qualified as Invocation | ||
import Demo.Scope qualified as Scope | ||
|
||
{------------------------------------------------------------------------------- | ||
Top-level | ||
-------------------------------------------------------------------------------} | ||
|
||
data Cmdline = Cmdline { | ||
cmdDemo :: Maybe Demo | ||
} | ||
deriving stock (Show) | ||
|
||
data Demo = | ||
DemoNiioWithout | ||
| DemoNiioUse | ||
| DemoCallsiteWithout | ||
| DemoCallsiteUse | ||
| DemoInvocationWithout | ||
| DemoInvocationUse Invocation.Example | ||
| DemoScopeUse Scope.Example | ||
| DemoCallbackWithout | ||
| DemoCallbackUse | ||
deriving stock (Show) | ||
|
||
getCmdline :: IO Cmdline | ||
getCmdline = execParser opts | ||
where | ||
opts :: ParserInfo Cmdline | ||
opts = info (parseCmdline <**> helper) $ mconcat [ | ||
fullDesc | ||
, header "Demo of the debuggable package" | ||
] | ||
|
||
{------------------------------------------------------------------------------- | ||
Parser | ||
-------------------------------------------------------------------------------} | ||
|
||
parseCmdline :: Parser Cmdline | ||
parseCmdline = | ||
Cmdline | ||
<$> optional parseDemo | ||
|
||
parseDemo :: Parser Demo | ||
parseDemo = subparser $ mconcat [ | ||
command' | ||
"niio" | ||
( parseWithoutUse | ||
(pure DemoNiioWithout) | ||
(pure DemoNiioUse) | ||
) | ||
"Demo Debug.NonInterleavedIO" | ||
, command' | ||
"callsite" | ||
( parseWithoutUse | ||
(pure DemoCallsiteWithout) | ||
(pure DemoCallsiteUse) | ||
) | ||
"Demo CallSite from Debug.Provenance" | ||
, command' | ||
"invocation" | ||
( parseWithoutUse | ||
(pure DemoInvocationWithout) | ||
(DemoInvocationUse <$> parseInvocationExample) | ||
) | ||
"Demo Invocation from Debug.Provenance" | ||
, command' | ||
"scope" | ||
( DemoScopeUse <$> parseScopeExample ) | ||
"Demo Debug.Provenance.Scope" | ||
, command' | ||
"callback" | ||
( parseWithoutUse | ||
(pure DemoCallbackWithout) | ||
(pure DemoCallbackUse) | ||
) | ||
"Demo Debug.Provenance.Callback" | ||
] | ||
|
||
parseWithoutUse :: Parser a -> Parser a -> Parser a | ||
parseWithoutUse without use = subparser $ mconcat [ | ||
command' "without-debuggable" without "Without debuggable" | ||
, command' "use-debuggable" use "Use debuggable" | ||
] | ||
|
||
parseInvocationExample :: Parser Invocation.Example | ||
parseInvocationExample = subparser $ mconcat [ | ||
command' "example1" (pure Invocation.Example1) "Example 1" | ||
, command' "example2" (pure Invocation.Example2) "Example 2" | ||
] | ||
|
||
parseScopeExample :: Parser Scope.Example | ||
parseScopeExample = subparser $ mconcat [ | ||
command' "example1" (pure Scope.Example1) "Example 1" | ||
, command' "example2" (pure Scope.Example2) "Example 2" | ||
, command' "example3" (pure Scope.Example3) "Example 3" | ||
, command' "example4" (pure Scope.Example4) "Example 4" | ||
] | ||
|
||
{------------------------------------------------------------------------------- | ||
Auxiliary optparse-applicative | ||
-------------------------------------------------------------------------------} | ||
|
||
command' :: String -> Parser a -> String -> Mod CommandFields a | ||
command' cmd parser desc = command cmd $ info (parser <**> helper) $ mconcat [ | ||
progDesc desc | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Demo (main) where | ||
|
||
import Cmdline | ||
|
||
import Demo.Callback qualified as Callback | ||
import Demo.Callsite qualified as Callsite | ||
import Demo.Invocation qualified as Invocation | ||
import Demo.NIIO qualified as NIIO | ||
import Demo.Scope qualified as Scope | ||
|
||
main :: IO () | ||
main = do | ||
Cmdline{cmdDemo} <- getCmdline | ||
case cmdDemo of | ||
Nothing -> putStrLn "Please select a demo (see --help)" | ||
Just demo -> | ||
case demo of | ||
DemoNiioWithout -> NIIO.withoutDebuggable | ||
DemoNiioUse -> NIIO.useDebuggable | ||
DemoCallsiteWithout -> Callsite.withoutDebuggable | ||
DemoCallsiteUse -> Callsite.useDebuggable | ||
DemoInvocationWithout -> Invocation.withoutDebuggable | ||
DemoInvocationUse ex -> Invocation.useDebuggable ex | ||
DemoScopeUse ex -> Scope.useDebuggable ex | ||
DemoCallbackWithout -> Callback.withoutDebuggable | ||
DemoCallbackUse -> Callback.useDebuggable | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module Demo.Callback ( | ||
withoutDebuggable | ||
, useDebuggable | ||
) where | ||
|
||
import GHC.Stack | ||
|
||
import Debug.NonInterleavedIO.Scoped qualified as Scoped | ||
import Debug.Provenance.Callback | ||
import Debug.Provenance.Scope | ||
|
||
{------------------------------------------------------------------------------- | ||
Without the library | ||
-------------------------------------------------------------------------------} | ||
|
||
f1 :: HasCallStack => (Int -> IO ()) -> IO () | ||
f1 k = f2 k | ||
|
||
f2 :: HasCallStack => (Int -> IO ()) -> IO () | ||
f2 k = scoped $ k 1 | ||
|
||
g1 :: HasCallStack => Int -> IO () | ||
g1 n = g2 n | ||
|
||
g2 :: HasCallStack => Int -> IO () | ||
g2 n = Scoped.putStrLn $ "n = " ++ show n ++ " at " ++ prettyCallStack callStack | ||
|
||
withoutDebuggable :: HasCallStack => IO () | ||
withoutDebuggable = f1 g1 | ||
|
||
{------------------------------------------------------------------------------- | ||
Using the library | ||
-------------------------------------------------------------------------------} | ||
|
||
h1 :: HasCallStack => Callback IO Int () -> IO () | ||
h1 k = h2 k | ||
|
||
h2 :: HasCallStack => Callback IO Int () -> IO () | ||
h2 k = scoped $ invokeCallback k 1 | ||
|
||
useDebuggable :: HasCallStack => IO () | ||
useDebuggable = h1 (callback g1) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module Demo.Callsite ( | ||
withoutDebuggable | ||
, useDebuggable | ||
) where | ||
|
||
import GHC.Stack (prettyCallStack, callStack) | ||
|
||
import Debug.Provenance | ||
|
||
{------------------------------------------------------------------------------- | ||
Without the library | ||
-------------------------------------------------------------------------------} | ||
|
||
f1 :: IO () | ||
f1 = f2 | ||
|
||
f2 :: HasCallStack => IO () | ||
f2 = f3 | ||
|
||
f3 :: HasCallStack => IO () | ||
f3 = putStrLn $ prettyCallStack callStack | ||
|
||
withoutDebuggable :: IO () | ||
withoutDebuggable = f1 | ||
|
||
{------------------------------------------------------------------------------- | ||
Using the library | ||
-------------------------------------------------------------------------------} | ||
|
||
g1 :: IO () | ||
g1 = g2 | ||
|
||
g2 :: HasCallStack => IO () | ||
g2 = g3 | ||
|
||
g3 :: HasCallStack => IO () | ||
g3 = print callSite | ||
|
||
useDebuggable :: IO () | ||
useDebuggable = g1 |
Oops, something went wrong.