never executed always true always false
    1 module HelVM.HelMA.Automata.LazyK.Automaton (
    2   run,
    3   runWithTerminator,
    4   realize,
    5   realizeWithTrue,
    6 ) where
    7 
    8 import           HelVM.HelMA.Automata.LazyK.Constants
    9 import           HelVM.HelMA.Automata.LazyK.Lambda
   10 import           HelVM.HelMA.Automata.LazyK.Reducer
   11 
   12 import           HelVM.HelMA.Automaton.IO.BusinessIO
   13 
   14 import           HelVM.HelIO.Control.Safe
   15 
   16 run :: BIO m => Lambda -> m ()
   17 run = runWithTerminator false
   18 
   19 runWithTerminator :: BIO m => Lambda -> Lambda -> m ()
   20 runWithTerminator terminator lambda = output terminator lambda =<< realizeWithTrue lambda
   21 
   22 realizeWithTrue :: MonadSafe m => Lambda -> m Natural
   23 realizeWithTrue = realize . flippedApply true
   24 
   25 realize :: MonadSafe m => Lambda -> m Natural
   26 realize = naturalSafe . flippedApply number0 . flippedApply Succ
   27 
   28 number0 :: Lambda
   29 number0 = Number 0
   30 
   31 naturalSafe :: MonadSafe m => Lambda -> m Natural
   32 naturalSafe (Number x) = pure x
   33 naturalSafe x          = liftErrorWithPrefix "Invalid output format. Output should be the list of Church numerals. " $ show x
   34 
   35 output :: BIO m => Lambda -> Lambda -> Natural -> m ()
   36 output terminator lambda number = check $ compare 256 number where
   37   check GT = wPutAsChar number *> runWithTerminator terminator (apply lambda terminator)
   38   check EQ = pass
   39   check LT = wLogStr (show number) *> wLogStr (show lambda)