-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a6ccb42
commit 5c926a3
Showing
10 changed files
with
159 additions
and
84 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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
----------------------------------------------------------------------------- | ||
-- | | ||
-- Module : Data.SBV.Tools.KDUtils | ||
-- Copyright : (c) Levent Erkok | ||
-- License : BSD3 | ||
-- Maintainer: [email protected] | ||
-- Stability : experimental | ||
-- | ||
-- Various KnuckleDrugger machinery. | ||
----------------------------------------------------------------------------- | ||
|
||
{-# LANGUAGE DerivingStrategies #-} | ||
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | ||
|
||
{-# OPTIONS_GHC -Wall -Werror #-} | ||
|
||
module Data.SBV.Tools.KDUtils ( | ||
KD, runKD, runKDWith | ||
, start, finish | ||
) where | ||
|
||
import Control.Monad.Reader (ReaderT, runReaderT) | ||
import Control.Monad.Trans (MonadIO(liftIO)) | ||
|
||
import Data.List (intercalate) | ||
import System.IO (hFlush, stdout) | ||
|
||
-- | Keeping track of KD options/state | ||
data KDConfig = KDConfig | ||
|
||
-- | Default KD-config | ||
defaultKDConfig :: KDConfig | ||
defaultKDConfig = KDConfig | ||
|
||
-- | Monad for running KnuckleDragger proofs in. | ||
newtype KD a = KD (ReaderT KDConfig IO a) | ||
deriving newtype (Applicative, Functor, Monad, MonadIO, MonadFail) | ||
|
||
-- | Run a KD proof, using the default configuration. | ||
runKD :: KD a -> IO a | ||
runKD = runKDWith defaultKDConfig | ||
|
||
-- | Run a KD proof, using the given configuration. | ||
runKDWith :: KDConfig -> KD a -> IO a | ||
runKDWith cfg (KD f) = runReaderT f cfg | ||
|
||
-- | Start a proof. We return the number of characters we printed, so the finisher can align the result. | ||
start :: Bool -> String -> [String] -> KD Int | ||
start newLine what nms = liftIO $ do putStr $ line ++ if newLine then "\n" else "" | ||
hFlush stdout | ||
return (length line) | ||
where tab = 2 * length (drop 1 nms) | ||
indent = replicate tab ' ' | ||
tag = what ++ ": " ++ intercalate "." nms | ||
line = indent ++ tag | ||
|
||
-- | Finish a proof. First argument is what we got from the call of 'start' above. | ||
finish :: String -> Int -> KD () | ||
finish what skip = liftIO $ putStrLn $ replicate (ribbonLength - skip) ' ' ++ what | ||
where -- Ideally an aestheticly pleasing length of the line. Perhaps this | ||
-- should be configurable, but this is good enough for now. | ||
ribbonLength :: Int | ||
ribbonLength = 40 |
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
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
Oops, something went wrong.