module Language.Haskell.Liquid.Transforms.Simplify (simplifyBounds) where

import Prelude hiding (error)
import Language.Haskell.Liquid.Types
import Language.Fixpoint.Types
import Language.Fixpoint.Types.Visitor
-- import Control.Applicative                 ((<$>))


simplifyBounds :: SpecType -> SpecType
simplifyBounds :: SpecType -> SpecType
simplifyBounds = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap UReft Reft -> UReft Reft
go
  where
    go :: UReft Reft -> UReft Reft
go UReft Reft
x       = UReft Reft
x { ur_reft :: Reft
ur_reft = Reft -> Reft
go' forall a b. (a -> b) -> a -> b
$ forall r. UReft r -> r
ur_reft UReft Reft
x }
    -- OLD go' (Reft (v, rs)) = Reft(v, filter (not . isBoundLike) rs)
    go' :: Reft -> Reft
go' (Reft (Symbol
v, Expr
p)) = (Symbol, Expr) -> Reft
Reft(Symbol
v, Expr -> Expr
dropBoundLike Expr
p)

dropBoundLike :: Expr -> Expr
dropBoundLike :: Expr -> Expr
dropBoundLike Expr
p
  | Expr -> Bool
isKvar Expr
p          = Expr
p
  | Expr -> Bool
isBoundLikePred Expr
p = forall a. Monoid a => a
mempty
  | Bool
otherwise         = Expr
p
  where
    isKvar :: Expr -> Bool
isKvar            = Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a. Foldable t => t a -> Bool
null forall b c a. (b -> c) -> (a -> b) -> a -> c
. Expr -> [KVar]
kvarsExpr

isBoundLikePred :: Expr -> Bool
isBoundLikePred :: Expr -> Bool
isBoundLikePred (PAnd [Expr]
ps) = Int
simplifyLen forall a. Ord a => a -> a -> Bool
<= forall (t :: * -> *) a. Foldable t => t a -> Int
length [Expr
p | Expr
p <- [Expr]
ps, Expr -> Bool
isImp Expr
p ]
isBoundLikePred Expr
_         = Bool
False

isImp :: Expr -> Bool
isImp :: Expr -> Bool
isImp (PImp Expr
_ Expr
_) = Bool
True
isImp Expr
_          = Bool
False

-- OLD isBoundLike (RConc pred)  = isBoundLikePred pred
-- OLD isBoundLike (RKvar _ _)   = False


-- OLD moreThan 0 _            = True
-- OLD moreThan _ []           = False
-- OLD moreThan i (True  : xs) = moreThan (i-1) xs
-- OLD moreThan i (False : xs) = moreThan i xs

simplifyLen :: Int
simplifyLen :: Int
simplifyLen = Int
5