Skip to content

Commit

Permalink
KD: make ribbonLength configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
LeventErkok committed Sep 10, 2024
1 parent 5c926a3 commit 9cc9132
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 additions & 9 deletions Data/SBV/Tools/KDUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,34 @@

{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE NamedFieldPuns #-}

{-# OPTIONS_GHC -Wall -Werror #-}

module Data.SBV.Tools.KDUtils (
KD, runKD, runKDWith
, start, finish
, KDConfig(..), defaultKDConfig
) where

import Control.Monad.Reader (ReaderT, runReaderT)
import Control.Monad.Reader (ReaderT, runReaderT, ask, MonadReader)
import Control.Monad.Trans (MonadIO(liftIO))

import Data.List (intercalate)
import System.IO (hFlush, stdout)

-- | Keeping track of KD options/state
data KDConfig = KDConfig
data KDConfig = KDConfig { kdRibbonLength :: Int -- ^ Lenght of the line as we print the proof
}

-- | Default KD-config
defaultKDConfig :: KDConfig
defaultKDConfig = KDConfig
defaultKDConfig = KDConfig { kdRibbonLength = 40
}

-- | Monad for running KnuckleDragger proofs in.
newtype KD a = KD (ReaderT KDConfig IO a)
deriving newtype (Applicative, Functor, Monad, MonadIO, MonadFail)
deriving newtype (Applicative, Functor, Monad, MonadIO, MonadReader KDConfig, MonadFail)

-- | Run a KD proof, using the default configuration.
runKD :: KD a -> IO a
Expand All @@ -56,8 +60,5 @@ start newLine what nms = liftIO $ do putStr $ line ++ if newLine then "\n" else

-- | 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
finish what skip = do KDConfig{kdRibbonLength} <- ask
liftIO $ putStrLn $ replicate (kdRibbonLength - skip) ' ' ++ what
2 changes: 1 addition & 1 deletion Data/SBV/Tools/KnuckleDragger.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module Data.SBV.Tools.KnuckleDragger (
-- * Faking proofs
, sorry
-- * Running KnuckleDragger proofs
, KD, runKD, runKDWith
, KD, runKD, runKDWith, KDConfig(..), defaultKDConfig
) where

import Control.Monad.Trans (liftIO)
Expand Down

0 comments on commit 9cc9132

Please sign in to comment.