{-# 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 :: 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 :: 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' :: 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 :: p -> p
fun p
childTerm = if p -> DataType
forall a. Data a => a -> DataType
dataTypeOf p
childTerm DataType -> DataType -> Bool
=== DataType
d then
Nat -> p -> p
forall a. Data a => Nat -> a -> a
approxGen' Nat
n' p
childTerm
else
p
childTerm
in (forall b. Data b => b -> b) -> a -> a
forall a. Data a => (forall b. Data b => b -> b) -> a -> a
gmapT 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