never executed always true always false
    1 {-# LANGUAGE ConstraintKinds #-}
    2 {-# LANGUAGE FunctionalDependencies #-}
    3 {-# LANGUAGE GADTs #-}
    4 {-# LANGUAGE TypeFamilies #-}
    5 
    6 {- |
    7 Module      : NITTA.Model.Problems.Refactor.BreakLoop
    8 Description : Refactoring for support computational loops
    9 Copyright   : (c) Aleksandr Penskoi, 2021
   10 License     : BSD3
   11 Maintainer  : aleksandr.penskoi@gmail.com
   12 Stability   : experimental
   13 
   14 BreakLoop example:
   15 
   16 > BreakLoop x o i
   17 
   18 before:
   19 
   20 > l@( Loop (X x) (O o) (I i) )
   21 
   22 after:
   23 
   24 > LoopEnd l (I i)
   25 > LoopBegin l (O o)
   26 
   27 For more details: 'NITTA.Intermediate.Functions.Loop'
   28 -}
   29 module NITTA.Model.Problems.Refactor.BreakLoop (
   30     BreakLoop (..),
   31     BreakLoopProblem (..),
   32     recLoop,
   33     recLoopIn,
   34     recLoopOut,
   35 ) where
   36 
   37 import Data.Set qualified as S
   38 import GHC.Generics
   39 import NITTA.Intermediate.Functions
   40 import NITTA.Intermediate.Types
   41 
   42 data BreakLoop v x = BreakLoop
   43     { loopX :: x
   44     -- ^ initial looped value
   45     , loopO :: S.Set v
   46     -- ^ output variables
   47     , loopI :: v
   48     -- ^ input variable
   49     }
   50     deriving (Generic, Eq)
   51 
   52 instance (Var v, Val x) => Show (BreakLoop v x) where
   53     show = ("BreakLoop: " <>) . show . recLoop
   54 
   55 class BreakLoopProblem u v x | u -> v x where
   56     breakLoopOptions :: u -> [BreakLoop v x]
   57     breakLoopOptions _ = []
   58 
   59     breakLoopDecision :: u -> BreakLoop v x -> u
   60     breakLoopDecision _ _ = error "not supported"
   61 
   62 recLoop BreakLoop{loopX, loopO, loopI} =
   63     packF $ Loop (X loopX) (O loopO) (I loopI)
   64 
   65 recLoopIn BreakLoop{loopX, loopO, loopI} =
   66     packF $ LoopEnd (Loop (X loopX) (O loopO) (I loopI)) (I loopI)
   67 
   68 recLoopOut BreakLoop{loopX, loopO, loopI} =
   69     packF $ LoopBegin (Loop (X loopX) (O loopO) (I loopI)) (O loopO)