|
1 | | -module PreludeHelper where |
2 | | - |
3 | | -import GHC.Stack |
4 | | - |
5 | | -import Control.Monad (guard) |
6 | | - |
7 | | -import Data.Monoid (Any(..)) |
8 | | -import Control.Applicative (Alternative(empty), Applicative(..), (<$>)) |
9 | | - |
10 | | --- import Debug.Trace (trace) |
11 | | - |
12 | | -import Control.Monad.Except (throwError, MonadError) |
13 | | - |
14 | | -import Debug.Pretty.Simple |
15 | | -import Text.Pretty.Simple |
16 | | - |
17 | | --- import Text.Pretty.Simple |
18 | | - |
19 | | -dPrinter a = pPrintStringOpt CheckColorTty defaultOutputOptionsDarkBg {outputOptionsCompact = True} $ show a |
20 | | - |
21 | | -dPrint a = pPrintStringOpt CheckColorTty defaultOutputOptionsDarkBg {outputOptionsCompact = True} $ a |
22 | | - |
23 | | -dTrace s a = pTraceOpt CheckColorTty defaultOutputOptionsDarkBg {outputOptionsCompact = True} s a |
24 | | - |
25 | | --- todo a = trace ("optimistically assume " ++ show a) $ pure a |
26 | | - |
27 | | -logg a = pure a |
28 | | --- logg a = trace ("-- " ++ show a) $ pure a |
29 | | --- logg a = dTrace ("-- " ++ show a) $ pure a |
30 | | --- logg a = dTrace ("-- " ++ show a) $ pure a |
31 | | - |
32 | | -loggg a = pure a |
33 | | --- loggg a = trace ("-- " ++ a) $ pure a |
34 | | --- loggg a = pTrace ("-- " ++ a) $ pure a |
35 | | --- loggg a = dTrace ("-- " ++ a) $ pure a |
36 | | - |
37 | | --- from: https://github.com/BU-CS320/Summer-2019/blob/master/assignments/HW4/src/HelpShow.hs |
38 | | -parenthesize :: Integer -- ^ the precedence level of outer expression |
39 | | - -> Integer -- ^ the precedence level of the current expression |
40 | | - -> String -- ^ string representation current expression |
41 | | - -> String -- ^ the properly (not necessarily fully) parenthesized current expression |
42 | | -parenthesize outerLevel curLevel showExp |
43 | | - | outerLevel < curLevel = "(" ++ showExp ++ ")" |
44 | | - | otherwise = showExp |
45 | | - |
46 | | - |
47 | | --- guardThrow :: HasCallStack => MonadError e m => Bool -> e -> m a -> m a |
48 | | --- guardThrow True s ma = ma |
49 | | --- guardThrow False s ma = throwError $ s -- ++ "\n" ++ prettyCallStack callStack |
50 | | - |
51 | | - |
52 | | --- TODO why is this not in the stdlib, also needs some string output? |
53 | | -justM :: Alternative f => Maybe a -> f a |
54 | | -justM (Just a) = pure a |
55 | | -justM _ = empty |
56 | | - |
57 | | - |
58 | | -errIo :: HasCallStack => String -> IO a |
59 | | -errIo s = |
60 | | - throwError $ userError $ "\n" ++ s ++ "\n" ++ prettyCallStack callStack |
61 | | --- TODO got to be something better then this? |
| 1 | +module PreludeHelper where |
| 2 | + |
| 3 | +import GHC.Stack |
| 4 | + |
| 5 | +import Control.Monad (guard) |
| 6 | + |
| 7 | +import Data.Monoid (Any(..)) |
| 8 | +import Control.Applicative (Alternative(empty), Applicative(..), (<$>)) |
| 9 | + |
| 10 | +-- import Debug.Trace (trace) |
| 11 | + |
| 12 | +import Control.Monad.Except (throwError, MonadError) |
| 13 | + |
| 14 | +import Debug.Pretty.Simple ( pTraceOpt ) |
| 15 | +import Text.Pretty.Simple |
| 16 | + ( CheckColorTty(CheckColorTty), |
| 17 | + OutputOptions(outputOptionsCompact), |
| 18 | + pPrintStringOpt, |
| 19 | + defaultOutputOptionsDarkBg ) |
| 20 | + |
| 21 | +-- import Text.Pretty.Simple |
| 22 | + |
| 23 | +dPrinter a = pPrintStringOpt CheckColorTty defaultOutputOptionsDarkBg {outputOptionsCompact = True} $ show a |
| 24 | + |
| 25 | +dPrint a = pPrintStringOpt CheckColorTty defaultOutputOptionsDarkBg {outputOptionsCompact = True} $ a |
| 26 | + |
| 27 | +dTrace s a = pTraceOpt CheckColorTty defaultOutputOptionsDarkBg {outputOptionsCompact = True} s a |
| 28 | + |
| 29 | +-- todo a = trace ("optimistically assume " ++ show a) $ pure a |
| 30 | + |
| 31 | +logg a = pure a |
| 32 | +-- logg a = trace ("-- " ++ show a) $ pure a |
| 33 | +-- logg a = dTrace ("-- " ++ show a) $ pure a |
| 34 | +-- logg a = dTrace ("-- " ++ show a) $ pure a |
| 35 | + |
| 36 | +loggg a = pure a |
| 37 | +-- loggg a = trace ("-- " ++ a) $ pure a |
| 38 | +-- loggg a = pTrace ("-- " ++ a) $ pure a |
| 39 | +-- loggg a = dTrace ("-- " ++ a) $ pure a |
| 40 | + |
| 41 | +-- from: https://github.com/BU-CS320/Summer-2019/blob/master/assignments/HW4/src/HelpShow.hs |
| 42 | +parenthesize :: Integer -- ^ the precedence level of outer expression |
| 43 | + -> Integer -- ^ the precedence level of the current expression |
| 44 | + -> String -- ^ string representation current expression |
| 45 | + -> String -- ^ the properly (not necessarily fully) parenthesized current expression |
| 46 | +parenthesize outerLevel curLevel showExp |
| 47 | + | outerLevel < curLevel = "(" ++ showExp ++ ")" |
| 48 | + | otherwise = showExp |
| 49 | + |
| 50 | + |
| 51 | +-- guardThrow :: HasCallStack => MonadError e m => Bool -> e -> m a -> m a |
| 52 | +-- guardThrow True s ma = ma |
| 53 | +-- guardThrow False s ma = throwError $ s -- ++ "\n" ++ prettyCallStack callStack |
| 54 | + |
| 55 | + |
| 56 | +-- TODO why is this not in the stdlib, also needs some string output? |
| 57 | +justM :: Alternative f => Maybe a -> f a |
| 58 | +justM (Just a) = pure a |
| 59 | +justM _ = empty |
| 60 | + |
| 61 | + |
| 62 | +errIo :: HasCallStack => String -> IO a |
| 63 | +errIo s = |
| 64 | + throwError $ userError $ "\n" ++ s ++ "\n" ++ prettyCallStack callStack |
| 65 | +-- TODO got to be something better then this? |
0 commit comments