{-# LANGUAGE ScopedTypeVariables,
FlexibleInstances, UndecidableInstances #-}
module Test.ChasingBottoms.Approx
( Approx(..)
) where
import Test.ChasingBottoms.Nat
import Data.Function
import Data.Generics
import qualified Data.List as List
class Approx a where
approxAll :: Nat -> a -> a
approx :: Nat -> a -> a
instance Data a => Approx a where
approxAll :: Nat -> a -> a
approxAll = Nat -> a -> a
forall a. Data a => Nat -> a -> a
approxAllGen
approx :: Nat -> a -> a
approx = Nat -> a -> a
forall a. Data a => Nat -> a -> a
approxGen
approxGen :: Data a => Nat -> a -> a
approxGen :: forall a. Data a => Nat -> a -> a
approxGen Nat
n | Nat
n Nat -> Nat -> Bool
forall a. Eq a => a -> a -> Bool
== Nat
0 = [Char] -> a -> a
forall a. HasCallStack => [Char] -> a
error [Char]
"approx 0 = _|_"
| Bool
otherwise =
\(a
x :: a) -> (forall b. Data b => b -> b) -> a -> a
forall a. Data a => (forall b. Data b => b -> b) -> a -> a
gmapT ((a -> a) -> b -> b
forall a b. (Typeable a, Typeable b) => (b -> b) -> a -> a
mkT (Nat -> a -> a
forall a. Data a => Nat -> a -> a
approxGen (Nat -> Nat
forall a. Enum a => a -> a
pred Nat
n) :: a -> a)) a
x
approxAllGen :: Data a => Nat -> a -> a
approxAllGen :: forall a. Data a => Nat -> a -> a
approxAllGen Nat
n | Nat
n Nat -> Nat -> Bool
forall a. Eq a => a -> a -> Bool
== Nat
0 = [Char] -> a -> a
forall a. HasCallStack => [Char] -> a
error [Char]
"approx 0 = _|_"
| Bool
otherwise = \a
x -> (forall b. Data b => b -> b) -> a -> a
forall a. Data a => (forall b. Data b => b -> b) -> a -> a
gmapT (Nat -> b -> b
forall a. Data a => Nat -> a -> a
approxAllGen (Nat -> Nat
forall a. Enum a => a -> a
pred Nat
n)) a
x
approxGen' :: Data a => Nat -> a -> a
approxGen' :: forall a. Data a => Nat -> a -> a
approxGen' Nat
n
| Nat
n Nat -> Nat -> Bool
forall a. Eq a => a -> a -> Bool
== Nat
0 = [Char] -> a -> a
forall a. HasCallStack => [Char] -> a
error [Char]
"approx 0 = _|_"
| Bool
otherwise = \a
x ->
let d :: DataType
d = a -> DataType
forall a. Data a => a -> DataType
dataTypeOf a
x
n' :: Nat
n' = Nat -> Nat
forall a. Enum a => a -> a
pred Nat
n
fun :: a -> a
fun a
childTerm = if a -> DataType
forall a. Data a => a -> DataType
dataTypeOf a
childTerm DataType -> DataType -> Bool
=== DataType
d then
Nat -> a -> a
forall a. Data a => Nat -> a -> a
approxGen' Nat
n' a
childTerm
else
a
childTerm
in (forall b. Data b => b -> b) -> a -> a
forall a. Data a => (forall b. Data b => b -> b) -> a -> a
gmapT b -> b
forall b. Data b => b -> b
fun a
x
where === :: DataType -> DataType -> Bool
(===) = DataRep -> DataRep -> Bool
forall a. Eq a => a -> a -> Bool
(==) (DataRep -> DataRep -> Bool)
-> (DataType -> DataRep) -> DataType -> DataType -> Bool
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` DataType -> DataRep
dataTypeRep