rerefined-0.8.0: Refinement types, again
Safe HaskellNone
LanguageGHC2021

Rerefined.Simplify.Core

Description

Core predicate simplification algorithm.

This is related to an NP-complete problem (see Boolean satisfiability problem). We focus on immediate, operation-reducing simplifications, and hope that the input is formed in such a way that our rules match.

In short, the simplifier is largely contextless. It inspects (usually) a single layer/depth at a time. So we can consistently simplify things like logical identities. But don't expect simplifications hard to spot with the naked eye.

Implementation pitfalls:

  • not extensible: only works for built-in logical & relational predicates
  • no protection against non-termination e.g. if a pair of transformations loop
  • very tedious to write. that's life

Internal module. Exports may change without warning. Try not to use.

Synopsis

Documentation

type family SimplifyStep p :: Maybe Type where ... Source #

Try to perform a single simplification step on the given predicate.

Returns Nothing if we were unable to simplify.

type family SimplifyAnd l r :: Maybe Type where ... Source #

type family OrElseAndL (r :: k1) (mp :: Maybe k) (cont :: Maybe Type) :: Maybe Type where ... Source #

Equations

OrElseAndL (r :: k1) ('Nothing :: Maybe k) cont = cont 
OrElseAndL (r :: k1) ('Just l' :: Maybe k) cont = 'Just (And l' r) 

type family OrElseAndR (l :: k) (mp :: Maybe k1) (cont :: Maybe Type) :: Maybe Type where ... Source #

Equations

OrElseAndR (l :: k) ('Nothing :: Maybe k1) cont = cont 
OrElseAndR (l :: k) ('Just r' :: Maybe k1) cont = 'Just (And l r') 

type family SimplifyOr l r :: Maybe Type where ... Source #

type family OrElseOrL (r :: k1) (mp :: Maybe k) (cont :: Maybe Type) :: Maybe Type where ... Source #

Equations

OrElseOrL (r :: k1) ('Nothing :: Maybe k) cont = cont 
OrElseOrL (r :: k1) ('Just l' :: Maybe k) cont = 'Just (Or l' r) 

type family OrElseOrR (l :: k) (mp :: Maybe k1) (cont :: Maybe Type) :: Maybe Type where ... Source #

Equations

OrElseOrR (l :: k) ('Nothing :: Maybe k1) cont = cont 
OrElseOrR (l :: k) ('Just r' :: Maybe k1) cont = 'Just (Or l r') 

type family OrElseNandL (r :: k1) (mp :: Maybe k) (cont :: Maybe Type) :: Maybe Type where ... Source #

Equations

OrElseNandL (r :: k1) ('Nothing :: Maybe k) cont = cont 
OrElseNandL (r :: k1) ('Just l' :: Maybe k) cont = 'Just (Nand l' r) 

type family OrElseNandR (l :: k) (mp :: Maybe k1) (cont :: Maybe Type) :: Maybe Type where ... Source #

Equations

OrElseNandR (l :: k) ('Nothing :: Maybe k1) cont = cont 
OrElseNandR (l :: k) ('Just r' :: Maybe k1) cont = 'Just (Nand l r') 

type family OrElseNorL (r :: k1) (mp :: Maybe k) (cont :: Maybe Type) :: Maybe Type where ... Source #

Equations

OrElseNorL (r :: k1) ('Nothing :: Maybe k) cont = cont 
OrElseNorL (r :: k1) ('Just l' :: Maybe k) cont = 'Just (Nor l' r) 

type family OrElseNorR (l :: k) (mp :: Maybe k1) (cont :: Maybe Type) :: Maybe Type where ... Source #

Equations

OrElseNorR (l :: k) ('Nothing :: Maybe k1) cont = cont 
OrElseNorR (l :: k) ('Just r' :: Maybe k1) cont = 'Just (Nor l r') 

type family SimplifyXor l r :: Maybe Type where ... Source #

type family OrElseXorL (r :: k1) (mp :: Maybe k) (cont :: Maybe Type) :: Maybe Type where ... Source #

Equations

OrElseXorL (r :: k1) ('Nothing :: Maybe k) cont = cont 
OrElseXorL (r :: k1) ('Just l' :: Maybe k) cont = 'Just (Xor l' r) 

type family OrElseXorR (l :: k) (mp :: Maybe k1) (cont :: Maybe Type) :: Maybe Type where ... Source #

Equations

OrElseXorR (l :: k) ('Nothing :: Maybe k1) cont = cont 
OrElseXorR (l :: k) ('Just r' :: Maybe k1) cont = 'Just (Xor l r') 

type family OrElseIfL (r :: k1) (mp :: Maybe k) (cont :: Maybe Type) :: Maybe Type where ... Source #

Equations

OrElseIfL (r :: k1) ('Nothing :: Maybe k) cont = cont 
OrElseIfL (r :: k1) ('Just l' :: Maybe k) cont = 'Just (If l' r) 

type family OrElseIfR (l :: k) (mp :: Maybe k1) (cont :: Maybe Type) :: Maybe Type where ... Source #

Equations

OrElseIfR (l :: k) ('Nothing :: Maybe k1) cont = cont 
OrElseIfR (l :: k) ('Just r' :: Maybe k1) cont = 'Just (If l r') 

type family OrElseIffL (r :: k1) (mp :: Maybe k) (cont :: Maybe Type) :: Maybe Type where ... Source #

Equations

OrElseIffL (r :: k1) ('Nothing :: Maybe k) cont = cont 
OrElseIffL (r :: k1) ('Just l' :: Maybe k) cont = 'Just (Iff l' r) 

type family OrElseIffR (l :: k) (mp :: Maybe k1) (cont :: Maybe Type) :: Maybe Type where ... Source #

Equations

OrElseIffR (l :: k) ('Nothing :: Maybe k1) cont = cont 
OrElseIffR (l :: k) ('Just r' :: Maybe k1) cont = 'Just (Iff l r') 

type family OrElseNot (mp :: Maybe k) (cont :: Maybe Type) :: Maybe Type where ... Source #

Equations

OrElseNot ('Just p' :: Maybe k) cont = 'Just (Not p') 
OrElseNot ('Nothing :: Maybe k) cont = cont