{-# LANGUAGE CPP #-}
{-# LANGUAGE CPP #-}
module Test.LeanCheck.Function.ShowFunction
(
showFunction
, showFunctionLine
, ShowFunction (..)
, bindtiersShow
, Binding
, bindings
, explainedBindings
, describedBindings
, clarifiedBindings
, Listable
)
where
import Test.LeanCheck.Core
import Test.LeanCheck.Error (errorToNothing)
import Test.LeanCheck.Utils.Types
import Test.LeanCheck.Stats (classifyOn)
import Data.Maybe
import Data.Function (on)
import Data.Word
import Data.Int
import Data.Ratio
import Data.Complex
import Data.Char (GeneralCategory)
import System.Exit (ExitCode)
import System.IO (IOMode, BufferMode, SeekMode)
import Foreign.C
#ifndef __HUGS__
import Data.List (intercalate, sortBy)
#else
import Data.List (sortBy)
intercalate :: [a] -> [[a]] -> [a]
intercalate xs xss = concat (intersperse xs xss)
where
intersperse :: a -> [a] -> [a]
intersperse _ [] = []
intersperse sep (x:xs) = x : prependToAll sep xs
where
prependToAll :: a -> [a] -> [a]
prependToAll _ [] = []
prependToAll sep (x:xs) = sep : x : prependToAll sep xs
#endif
type Binding = ([String], Maybe String)
class ShowFunction a where
bindtiers :: a -> [[Binding]]
bindings :: ShowFunction a => a -> [Binding]
bindings :: forall a. ShowFunction a => a -> [Binding]
bindings = forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. ShowFunction a => a -> [[Binding]]
bindtiers
bindtiersShow :: Show a => a -> [[Binding]]
a
x = [[([],forall a. a -> Maybe a
errorToNothing forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> String
show a
x)]]
instance ShowFunction () where bindtiers :: () -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Bool where bindtiers :: Bool -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Int where bindtiers :: Int -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Word where bindtiers :: Word -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Integer where bindtiers :: Integer -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Char where bindtiers :: Char -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Float where bindtiers :: Float -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Double where bindtiers :: Double -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Ordering where bindtiers :: Ordering -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance Show a => ShowFunction [a] where bindtiers :: [a] -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance Show a => ShowFunction (Maybe a) where bindtiers :: Maybe a -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance (Show a, Show b) => ShowFunction (Either a b) where
bindtiers :: Either a b -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance (Show a, Show b) => ShowFunction (a,b) where
bindtiers :: (a, b) -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance (Show a, Listable a, ShowFunction b) => ShowFunction (a->b) where
bindtiers :: (a -> b) -> [[Binding]]
bindtiers a -> b
f = forall a b. (a -> [[b]]) -> [[a]] -> [[b]]
concatMapT a -> [[Binding]]
bindtiersFor forall a. Listable a => [[a]]
tiers
where bindtiersFor :: a -> [[Binding]]
bindtiersFor a
x = forall {t} {a} {b}. (t -> a) -> (t, b) -> (a, b)
mapFst (forall a. Show a => a -> String
show a
xforall a. a -> [a] -> [a]
:) forall a b. (a -> b) -> [[a]] -> [[b]]
`mapT` forall a. ShowFunction a => a -> [[Binding]]
bindtiers (a -> b
f a
x)
mapFst :: (t -> a) -> (t, b) -> (a, b)
mapFst t -> a
f (t
x,b
y) = (t -> a
f t
x, b
y)
paren :: String -> String
paren :: String -> String
paren String
s = String
"(" forall a. [a] -> [a] -> [a]
++ String
s forall a. [a] -> [a] -> [a]
++ String
")"
showTuple :: [String] -> String
showTuple :: [String] -> String
showTuple [String
x] = String
x
showTuple [String]
xs | forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (forall a. Eq a => a -> a -> Bool
== String
"_") [String]
xs = String
"_"
| Bool
otherwise = String -> String
paren forall a b. (a -> b) -> a -> b
$ forall a. [a] -> [[a]] -> [a]
intercalate String
"," [String]
xs
showBindings :: [Binding] -> [String]
showBindings :: [Binding] -> [String]
showBindings [Binding]
bs = [ [String] -> String
showTuple [String]
as forall a. [a] -> [a] -> [a]
++ String
" -> " forall a. [a] -> [a] -> [a]
++ String
r | ([String]
as, Just String
r) <- [Binding]
bs ]
showNBindings :: Bool -> Int -> [Binding] -> [String]
showNBindings :: Bool -> Int -> [Binding] -> [String]
showNBindings Bool
infinite Int
n [Binding]
bs' = forall a. Int -> [a] -> [a]
take Int
n [String]
bs
forall a. [a] -> [a] -> [a]
++ [String
"..." | Bool
infinite Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => t a -> Int
length [String]
bs forall a. Ord a => a -> a -> Bool
> Int
n]
where
bs :: [String]
bs = [Binding] -> [String]
showBindings [Binding]
bs'
isValue :: ShowFunction a => a -> Bool
isValue :: forall a. ShowFunction a => a -> Bool
isValue a
f = case forall a. ShowFunction a => a -> [Binding]
bindings a
f of
[([],Maybe String
_)] -> Bool
True
[Binding]
_ -> Bool
False
showValueOf :: ShowFunction a => a -> String
showValueOf :: forall a. ShowFunction a => a -> String
showValueOf a
x = case forall a b. (a, b) -> b
snd forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> a
head forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. ShowFunction a => a -> [Binding]
bindings forall a b. (a -> b) -> a -> b
$ a
x of
Maybe String
Nothing -> String
"undefined"
Just String
x' -> String
x'
showFunction :: ShowFunction a => Int -> a -> String
showFunction :: forall a. ShowFunction a => Int -> a -> String
showFunction Int
n = forall a. ShowFunction a => Bool -> Int -> Int -> a -> String
showFunctionL Bool
False (Int
nforall a. Num a => a -> a -> a
*Int
nforall a. Num a => a -> a -> a
+Int
1) Int
n
showFunctionLine :: ShowFunction a => Int -> a -> String
showFunctionLine :: forall a. ShowFunction a => Int -> a -> String
showFunctionLine Int
n = forall a. ShowFunction a => Bool -> Int -> Int -> a -> String
showFunctionL Bool
True (Int
nforall a. Num a => a -> a -> a
*Int
nforall a. Num a => a -> a -> a
+Int
1) Int
n
isUndefined :: ShowFunction a => Int -> a -> Bool
isUndefined :: forall a. ShowFunction a => Int -> a -> Bool
isUndefined Int
m = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (forall a. Maybe a -> Bool
isNothing forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Int -> [a] -> [a]
take Int
m forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. ShowFunction a => a -> [Binding]
bindings
isConstant :: ShowFunction a => Int -> a -> Bool
isConstant :: forall a. ShowFunction a => Int -> a -> Bool
isConstant Int
m a
f = case forall a. Int -> [a] -> [a]
take Int
m forall a b. (a -> b) -> a -> b
$ forall a. ShowFunction a => a -> [Binding]
bindings a
f of
[] -> Bool
False
(([String]
_,Maybe String
r'):[Binding]
bs) -> forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (\([String]
_,Maybe String
r) -> Maybe String
r forall a. Eq a => a -> a -> Bool
== Maybe String
r') [Binding]
bs
showConstant :: ShowFunction a => Int -> a -> String
showConstant :: forall a. ShowFunction a => Int -> a -> String
showConstant Int
m a
f = String
"\\" forall a. [a] -> [a] -> [a]
++ [String] -> String
unwords [String]
vs forall a. [a] -> [a] -> [a]
++ String
" -> " forall a. [a] -> [a] -> [a]
++ forall a. a -> Maybe a -> a
fromMaybe String
"undefined" Maybe String
r
where
([String]
as,Maybe String
r) = forall a. [a] -> a
head forall a b. (a -> b) -> a -> b
$ forall a. ShowFunction a => a -> [Binding]
bindings a
f
vs :: [String]
vs = forall a. Int -> a -> [a]
replicate (forall (t :: * -> *) a. Foldable t => t a -> Int
length [String]
as) String
"_"
showFunctionL :: ShowFunction a => Bool -> Int -> Int -> a -> String
showFunctionL :: forall a. ShowFunction a => Bool -> Int -> Int -> a -> String
showFunctionL Bool
singleLine Int
m Int
n a
f | forall a. ShowFunction a => a -> Bool
isValue a
f = forall a. ShowFunction a => a -> String
showValueOf a
f
showFunctionL Bool
singleLine Int
m Int
n a
f | forall a. ShowFunction a => Int -> a -> Bool
isConstant Int
m a
f = forall a. ShowFunction a => Int -> a -> String
showConstant Int
m a
f
showFunctionL Bool
singleLine Int
m Int
n a
f | Bool
otherwise = String
lambdaPat forall a. [a] -> [a] -> [a]
++ String
caseExp
where
lambdaPat :: String
lambdaPat = String
"\\" forall a. [a] -> [a] -> [a]
++ [String] -> String
unwords [String]
vs forall a. [a] -> [a] -> [a]
++ String
" -> "
casePat :: String
casePat = String
"case " forall a. [a] -> [a] -> [a]
++ [String] -> String
showTuple (forall a. (a -> Bool) -> [a] -> [a]
filter (forall a. Eq a => a -> a -> Bool
/= String
"_") [String]
vs) forall a. [a] -> [a] -> [a]
++ String
" of"
([String]
vs, [Binding]
bindings) = forall a.
ShowFunction a =>
Int -> Int -> a -> ([String], [Binding])
clarifiedBindings Int
m Int
n a
f
bs :: [String]
bs = Bool -> Int -> [Binding] -> [String]
showNBindings (forall (t :: * -> *) a. Foldable t => t a -> Int
length [Binding]
bindings forall a. Ord a => a -> a -> Bool
>= Int
m) Int
n [Binding]
bindings
sep :: String
sep | Bool
singleLine = String
" "
| Bool
otherwise = String
"\n"
cases :: String
cases | Bool
singleLine = forall a. [a] -> [[a]] -> [a]
intercalate String
"; " [String]
bs
| Bool
otherwise = [String] -> String
unlines
forall a b. (a -> b) -> a -> b
$ (forall a. Int -> a -> [a]
replicate (forall (t :: * -> *) a. Foldable t => t a -> Int
length String
lambdaPat) Char
' ' forall a. [a] -> [a] -> [a]
++) forall a b. (a -> b) -> [a] -> [b]
`map` [String]
bs
caseExp :: String
caseExp = if forall a. ShowFunction a => Int -> a -> Bool
isUndefined Int
m a
f
then String
"undefined"
else String
casePat forall a. [a] -> [a] -> [a]
++ String
sep forall a. [a] -> [a] -> [a]
++ String
cases
instance (Show a, Show b, Show c)
=> ShowFunction (a,b,c) where bindtiers :: (a, b, c) -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance (Show a, Show b, Show c, Show d)
=> ShowFunction (a,b,c,d) where bindtiers :: (a, b, c, d) -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance (Show a, Show b, Show c, Show d, Show e)
=> ShowFunction (a,b,c,d,e) where bindtiers :: (a, b, c, d, e) -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
#ifndef __HUGS__
instance (Show a, Show b, Show c, Show d, Show e, Show f)
=> ShowFunction (a,b,c,d,e,f) where bindtiers :: (a, b, c, d, e, f) -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g)
=> ShowFunction (a,b,c,d,e,f,g) where bindtiers :: (a, b, c, d, e, f, g) -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h)
=> ShowFunction (a,b,c,d,e,f,g,h) where bindtiers :: (a, b, c, d, e, f, g, h) -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ( Show a, Show b, Show c, Show d
, Show e, Show f, Show g, Show h
, Show i )
=> ShowFunction (a,b,c,d,e,f,g,h,i) where bindtiers :: (a, b, c, d, e, f, g, h, i) -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ( Show a, Show b, Show c, Show d
, Show e, Show f, Show g, Show h
, Show i, Show j )
=> ShowFunction (a,b,c,d,e,f,g,h,i,j) where bindtiers :: (a, b, c, d, e, f, g, h, i, j) -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ( Show a, Show b, Show c, Show d
, Show e, Show f, Show g, Show h
, Show i, Show j, Show k )
=> ShowFunction (a,b,c,d,e,f,g,h,i,j,k) where bindtiers :: (a, b, c, d, e, f, g, h, i, j, k) -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ( Show a, Show b, Show c, Show d
, Show e, Show f, Show g, Show h
, Show i, Show j, Show k, Show l )
=> ShowFunction (a,b,c,d,e,f,g,h,i,j,k,l) where
bindtiers :: (a, b, c, d, e, f, g, h, i, j, k, l) -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
#endif
instance (Integral a, Show a) => ShowFunction (Ratio a) where
bindtiers :: Ratio a -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance (RealFloat a, Show a) => ShowFunction (Complex a) where
bindtiers :: Complex a -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Int8 where bindtiers :: Int8 -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Int16 where bindtiers :: Int16 -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Int32 where bindtiers :: Int32 -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Int64 where bindtiers :: Int64 -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Word8 where bindtiers :: Word8 -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Word16 where bindtiers :: Word16 -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Word32 where bindtiers :: Word32 -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Word64 where bindtiers :: Word64 -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Nat where bindtiers :: Nat -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Nat1 where bindtiers :: Nat1 -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Nat2 where bindtiers :: Nat2 -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Nat3 where bindtiers :: Nat3 -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Nat4 where bindtiers :: Nat4 -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Nat5 where bindtiers :: Nat5 -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Nat6 where bindtiers :: Nat6 -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Nat7 where bindtiers :: Nat7 -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Int1 where bindtiers :: Int1 -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Int2 where bindtiers :: Int2 -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Int3 where bindtiers :: Int3 -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Int4 where bindtiers :: Int4 -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Word1 where bindtiers :: Word1 -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Word2 where bindtiers :: Word2 -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Word3 where bindtiers :: Word3 -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Word4 where bindtiers :: Word4 -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Natural where bindtiers :: Natural -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Letter where bindtiers :: Letter -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction AlphaNum where bindtiers :: AlphaNum -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Digit where bindtiers :: Digit -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Alpha where bindtiers :: Alpha -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Upper where bindtiers :: Upper -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Lower where bindtiers :: Lower -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Space where bindtiers :: Space -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Spaces where bindtiers :: Spaces -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Lowers where bindtiers :: Lowers -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Uppers where bindtiers :: Uppers -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Alphas where bindtiers :: Alphas -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Digits where bindtiers :: Digits -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction AlphaNums where bindtiers :: AlphaNums -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction Letters where bindtiers :: Letters -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance Show a => ShowFunction (X a) where bindtiers :: X a -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance Show a => ShowFunction (Xs a) where bindtiers :: Xs a -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance Show a => ShowFunction (Set a) where bindtiers :: Set a -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance Show a => ShowFunction (Bag a) where bindtiers :: Bag a -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance Show a => ShowFunction (NoDup a) where bindtiers :: NoDup a -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance (Show a, Show b) => ShowFunction (Map a b) where
bindtiers :: Map a b -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction ExitCode where bindtiers :: ExitCode -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction SeekMode where bindtiers :: SeekMode -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction IOMode where bindtiers :: IOMode -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction BufferMode where bindtiers :: BufferMode -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction GeneralCategory where bindtiers :: GeneralCategory -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction CChar where bindtiers :: CChar -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction CSChar where bindtiers :: CSChar -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction CUChar where bindtiers :: CUChar -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction CShort where bindtiers :: CShort -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction CUShort where bindtiers :: CUShort -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction CInt where bindtiers :: CInt -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction CUInt where bindtiers :: CUInt -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction CLong where bindtiers :: CLong -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction CULong where bindtiers :: CULong -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction CPtrdiff where bindtiers :: CPtrdiff -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction CSize where bindtiers :: CSize -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction CWchar where bindtiers :: CWchar -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction CSigAtomic where bindtiers :: CSigAtomic -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction CLLong where bindtiers :: CLLong -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction CULLong where bindtiers :: CULLong -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction CIntPtr where bindtiers :: CIntPtr -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction CUIntPtr where bindtiers :: CUIntPtr -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction CIntMax where bindtiers :: CIntMax -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction CUIntMax where bindtiers :: CUIntMax -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction CClock where bindtiers :: CClock -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction CTime where bindtiers :: CTime -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction CFloat where bindtiers :: CFloat -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction CDouble where bindtiers :: CDouble -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
#if __GLASGOW_HASKELL__ >= 802
instance ShowFunction CBool where bindtiers :: CBool -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
#endif
#if __GLASGOW_HASKELL__
instance ShowFunction CUSeconds where bindtiers :: CUSeconds -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
instance ShowFunction CSUSeconds where bindtiers :: CSUSeconds -> [[Binding]]
bindtiers = forall a. Show a => a -> [[Binding]]
bindtiersShow
#endif
clarifiedBindings :: ShowFunction a => Int -> Int -> a -> ([String],[Binding])
clarifiedBindings :: forall a.
ShowFunction a =>
Int -> Int -> a -> ([String], [Binding])
clarifiedBindings Int
m Int
n = [Binding] -> ([String], [Binding])
clarifyBindings forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. ShowFunction a => Int -> Int -> a -> [Binding]
describedBindings Int
m Int
n
clarifyBindings :: [Binding] -> ([String],[Binding])
clarifyBindings :: [Binding] -> ([String], [Binding])
clarifyBindings [Binding]
bs = ([Bool] -> [String]
varnamesByUsage [Bool]
used, forall a b. (a -> b) -> [a] -> [b]
map (forall {t} {a} {b}. (t -> a) -> (t, b) -> (a, b)
mapFst forall a b. (a -> b) -> a -> b
$ forall a. [Bool] -> [a] -> [a]
select [Bool]
used) [Binding]
bs)
where
mapFst :: (t -> a) -> (t, b) -> (a, b)
mapFst t -> a
f (t
x,b
y) = (t -> a
f t
x, b
y)
used :: [Bool]
used = [Binding] -> [Bool]
usedArgs [Binding]
bs
varnamesByUsage :: [Bool] -> [String]
varnamesByUsage :: [Bool] -> [String]
varnamesByUsage = forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith String -> Bool -> String
used [String]
varnames
where
used :: String -> Bool -> String
used String
s Bool
False = String
"_"
used String
s Bool
True = String
s
varnames :: [String]
varnames = [String
"x",String
"y",String
"z",String
"w"] forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map (forall a. [a] -> [a] -> [a]
++String
"'") [String]
varnames
usedArgs :: [Binding] -> [Bool]
usedArgs :: [Binding] -> [Bool]
usedArgs = forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldr1 (forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Bool -> Bool -> Bool
(||))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map (forall a b. (a -> b) -> [a] -> [b]
map (forall a. Eq a => a -> a -> Bool
/= String
"_") forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst)
describedBindings :: ShowFunction a => Int -> Int -> a -> [Binding]
describedBindings :: forall a. ShowFunction a => Int -> Int -> a -> [Binding]
describedBindings Int
m Int
n a
f
| forall (t :: * -> *) a. Foldable t => t a -> Int
length [Binding]
bs1 forall a. Ord a => a -> a -> Bool
<= Int
n = [Binding]
bs1
| Bool
otherwise = [Binding]
bs0
where
bs0 :: [Binding]
bs0 = forall a. Int -> [a] -> [a]
take Int
m forall a b. (a -> b) -> a -> b
$ forall a. ShowFunction a => a -> [Binding]
bindings a
f
bs1 :: [Binding]
bs1 = [Binding] -> [Binding]
describeBindings [Binding]
bs0
describeBindings :: [Binding] -> [Binding]
describeBindings :: [Binding] -> [Binding]
describeBindings [Binding]
bs = forall a. [a] -> a
head forall a b. (a -> b) -> a -> b
$ forall b a. Ord b => (a -> b) -> [a] -> [a]
sortOn forall (t :: * -> *) a. Foldable t => t a -> Int
length forall a b. (a -> b) -> a -> b
$
[ [Binding]
bs
, [Binding] -> [Binding]
explainBindings [Binding]
bs
, [Binding] -> [Binding]
explainBindings forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b a. Ord b => (a -> b) -> [a] -> [a]
sortOn forall (t :: * -> *) a. Foldable t => t a -> Int
length forall a b. (a -> b) -> a -> b
$ forall b a. Eq b => (a -> b) -> [a] -> [[a]]
classifyOn forall a b. (a, b) -> b
snd [Binding]
bs
]
explainedBindings :: ShowFunction a => Int -> a -> [Binding]
explainedBindings :: forall a. ShowFunction a => Int -> a -> [Binding]
explainedBindings Int
m = [Binding] -> [Binding]
explainBindings forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Int -> [a] -> [a]
take Int
m forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. ShowFunction a => a -> [Binding]
bindings
explainBindings :: [Binding] -> [Binding]
explainBindings :: [Binding] -> [Binding]
explainBindings = [Binding] -> [Binding] -> [Binding]
explain []
where
explain :: [Binding] -> [Binding] -> [Binding]
explain :: [Binding] -> [Binding] -> [Binding]
explain [Binding]
bs' [] = forall a. [a] -> [a]
reverse [Binding]
bs'
explain [Binding]
bs' (([String]
as,Maybe String
r):[Binding]
bs) = [Binding] -> [Binding] -> [Binding]
explain ([Binding]
bs''forall a. [a] -> [a] -> [a]
++[Binding]
bs') [Binding
b | Binding
b <- [Binding]
bs
, forall a. (a -> Bool) -> [a] -> Bool
none (Binding
b Binding -> Binding -> Bool
<~~) [Binding]
bs'']
where
bs'' :: [Binding]
bs'' = forall a. (a -> a -> Bool) -> [a] -> [a]
discardLater Binding -> Binding -> Bool
(<~~)
[ ([String]
gas,Maybe String
r) | [String]
gas <- [String] -> [[String]]
generalizations [String]
as
, forall (t :: * -> *). Foldable t => t Bool -> Bool
and [Maybe String
r' forall a. Eq a => a -> a -> Bool
== Maybe String
r | ([String]
as',Maybe String
r') <- [Binding]
bs, [String]
as' [String] -> [String] -> Bool
<~ [String]
gas] ]
generalizations :: [String] -> [[String]]
generalizations :: [String] -> [[String]]
generalizations [] = [[]]
generalizations (String
v:[String]
vs) = forall a b. (a -> b) -> [a] -> [b]
map (String
"_"forall a. a -> [a] -> [a]
:) [[String]]
gvs forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map (String
vforall a. a -> [a] -> [a]
:) [[String]]
gvs
where
gvs :: [[String]]
gvs = [String] -> [[String]]
generalizations [String]
vs
(<~) :: [String] -> [String] -> Bool
[] <~ :: [String] -> [String] -> Bool
<~ [] = Bool
True
(String
v:[String]
vs) <~ (String
"_":[String]
ws) = [String]
vs [String] -> [String] -> Bool
<~ [String]
ws
(String
v:[String]
vs) <~ (String
w:[String]
ws) = String
v forall a. Eq a => a -> a -> Bool
== String
w Bool -> Bool -> Bool
&& [String]
vs [String] -> [String] -> Bool
<~ [String]
ws
[String]
_ <~ [String]
_ = Bool
False
(<~~) :: Binding -> Binding -> Bool
([String]
as,Maybe String
r) <~~ :: Binding -> Binding -> Bool
<~~ ([String]
as',Maybe String
r') = [String]
as [String] -> [String] -> Bool
<~ [String]
as' Bool -> Bool -> Bool
&& Maybe String
r forall a. Eq a => a -> a -> Bool
== Maybe String
r'
discard :: (a -> Bool) -> [a] -> [a]
discard :: forall a. (a -> Bool) -> [a] -> [a]
discard a -> Bool
p = forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Bool
p)
discardLater :: (a -> a -> Bool) -> [a] -> [a]
discardLater :: forall a. (a -> a -> Bool) -> [a] -> [a]
discardLater a -> a -> Bool
(?>) = [a] -> [a]
dl
where
dl :: [a] -> [a]
dl [] = []
dl (a
x:[a]
xs) = a
x forall a. a -> [a] -> [a]
: forall a. (a -> Bool) -> [a] -> [a]
discard (a -> a -> Bool
?> a
x) ([a] -> [a]
dl [a]
xs)
none :: (a -> Bool) -> [a] -> Bool
none :: forall a. (a -> Bool) -> [a] -> Bool
none a -> Bool
p = Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any a -> Bool
p
sortOn :: Ord b => (a -> b) -> [a] -> [a]
sortOn :: forall b a. Ord b => (a -> b) -> [a] -> [a]
sortOn a -> b
f = forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy (forall a. Ord a => a -> a -> Ordering
compare forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` a -> b
f)
select :: [Bool] -> [a] -> [a]
select :: forall a. [Bool] -> [a] -> [a]
select [] [a]
_ = []
select [Bool]
_ [] = []
select (Bool
p:[Bool]
ps) (a
x:[a]
xs) = if Bool
p then a
x forall a. a -> [a] -> [a]
: [a]
xs' else [a]
xs' where xs' :: [a]
xs' = forall a. [Bool] -> [a] -> [a]
select [Bool]
ps [a]
xs