never executed always true always false
    1 module HelVM.HelMA.Automata.LazyK.Automaton
    2   ( realize
    3   , realizeWithTrue
    4   , runAutomat
    5   , runWithTerminator
    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.Eff.MonadEff
   13 
   14 import           HelVM.HelIO.Control.Safe
   15 
   16 import           Control.Monad.Logger
   17 
   18 runAutomat ∷ AppSafeEff m ⇒ Lambda → m ()
   19 runAutomat = runWithTerminator false
   20 
   21 runWithTerminator ∷ AppSafeEff m ⇒ Lambda → Lambda → m ()
   22 runWithTerminator terminator lambda = output terminator lambda =<< realizeWithTrue lambda
   23 
   24 realizeWithTrue ∷ MonadSafe m ⇒ Lambda → m Natural
   25 realizeWithTrue = realize . flippedApply true
   26 
   27 realize ∷ MonadSafe m ⇒ Lambda → m Natural
   28 realize = naturalSafe . flippedApply number0 . flippedApply Succ
   29 
   30 number0 ∷ Lambda
   31 number0 = Number 0
   32 
   33 naturalSafe ∷ MonadSafe m ⇒ Lambda → m Natural
   34 naturalSafe (Number x) = pure x
   35 naturalSafe x          = liftErrorWithPrefix "Invalid output format. Output should be the list of Church numerals. " $ show x
   36 
   37 output ∷ AppSafeEff m ⇒ Lambda → Lambda → Natural → m ()
   38 output terminator lambda number = check $ compare 256 number where
   39   check GT = putAsChar number *> runWithTerminator terminator (apply lambda terminator)
   40   check EQ = pass
   41   check LT = logInfoN (show number) *> logInfoN (show lambda)