packages feed

rest-rewrite-0.2.0: src/Language/REST/OCToAbstract.hs

{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ImplicitParams #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}

module Language.REST.OCToAbstract where

import Data.Hashable

import Control.Monad.Identity

import Language.REST.OCAlgebra
import qualified Language.REST.WQOConstraints as OC
import Language.REST.Types
import Language.REST.SMT (ToSMTVar)

showHash :: Show a => a -> String
showHash = show . hash . show

lift :: forall impl base lifted m . (ToSMTVar base Int, Ord base, Eq base, Hashable base, Show lifted, Show base, Show (impl base)) =>
     OC.WQOConstraints impl m
  -> OC.ConstraintGen impl base lifted Identity
  -> OCAlgebra (impl base) lifted m
lift oc cgen =
  OCAlgebra {
    isSat  = isSat'
  , top    = top'
  , refine = refine'
  , union  = OC.union oc
  , notStrongerThan = OC.notStrongerThan oc
  }
  where
    isSat' :: impl base -> m Bool
    isSat' aoc = OC.isSatisfiable oc aoc

    top' :: impl base
    top' = OC.noConstraints oc

    refine' :: impl base -> lifted -> lifted -> impl base
    refine' c t u =
      let
        pair   = runIdentity $ cgen oc GTE top' t u
        result = OC.intersect oc c pair
      in
        result