-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Automatic inductive functional programmer by systematic search -- -- MagicHaskeller is an inductive functional programming system for -- Haskell. This package contains the MagicHaskeller library, which can -- be used within GHCi or as an API for inductive program synthesis. It -- also contains the MagicHaskeller executable that is a standalone -- synthesis program which can be used interactively or as a backend -- server, and the MagicHaskeller.cgi executable that is a CGI frontend -- for providing the Web interface. @package MagicHaskeller @version 0.9.6.4.4 module MagicHaskeller.GetTime batchWrite :: FilePath -> [IO a] -> IO () batchRun :: [IO a] -> IO [Integer] time :: IO a -> IO (a, Integer) showZero :: [Char] -> [Char] showCPUTime :: Integer -> String lenPrec :: Int module MagicHaskeller.FastRatio data Ratio a (:%) :: !Integer -> !Integer -> Ratio a type Rational = Ratio Integer (%) :: Integral a => a -> a -> Ratio a numerator :: Integral a => Ratio a -> a denominator :: Integral a => Ratio a -> a notANumber :: Ratio a reduce :: Integer -> Integer -> Ratio a choose :: Ratio a -> Ratio a instance GHC.Classes.Ord (MagicHaskeller.FastRatio.Ratio a) instance GHC.Classes.Eq (MagicHaskeller.FastRatio.Ratio a) instance GHC.Real.Integral a => GHC.Num.Num (MagicHaskeller.FastRatio.Ratio a) instance GHC.Real.Integral a => GHC.Real.Fractional (MagicHaskeller.FastRatio.Ratio a) instance GHC.Real.Integral a => GHC.Real.RealFrac (MagicHaskeller.FastRatio.Ratio a) instance (GHC.Show.Show a, GHC.Real.Integral a) => GHC.Show.Show (MagicHaskeller.FastRatio.Ratio a) instance GHC.Real.Integral a => GHC.Real.Real (MagicHaskeller.FastRatio.Ratio a) instance GHC.Real.Integral a => GHC.Enum.Enum (MagicHaskeller.FastRatio.Ratio a) module Control.Monad.Search.Combinatorial newtype Matrix a Mx :: Stream (Bag a) -> Matrix a [unMx] :: Matrix a -> Stream (Bag a) (/\) :: Monad m => (a -> m b) -> (t -> m a) -> t -> m b (\/) :: MonadPlus m => (t -> m a) -> (t -> m a) -> t -> m a newtype Recomp a Rc :: (Int -> Bag a) -> Recomp a [unRc] :: Recomp a -> Int -> Bag a newtype RecompT m a RcT :: (Int -> m (Bag a)) -> RecompT m a [unRcT] :: RecompT m a -> Int -> m (Bag a) rcToMx :: Recomp a -> Matrix a mxToRc :: Matrix a -> Recomp a class (Delay m, MonadPlus m, Functor m) => Search m where catBags = mapDepth concat mergesortDepthWithBy combiner comp = mapDepth (mergesortWithBy combiner comp) fromRc :: Search m => Recomp a -> m a toRc :: Search m => m a -> Recomp a fromMx :: Search m => Matrix a -> m a toMx :: Search m => m a -> Matrix a fromDB :: Search m => DBound a -> m a fromDF :: Search m => [a] -> m a toDF :: Search m => m a -> [a] -- | mapDepth applies a function to the bag at each depth. mapDepth :: Search m => (Bag a -> Bag b) -> m a -> m b -- | catBags flattens each bag. catBags :: Search m => m (Bag a) -> m a -- | mergesortDepthWithBy converts bags to sets, by (possibly -- sorting each bag and) removing duplicates. Efficiency on lists with -- lots of duplicates is required. mergesortDepthWithBy :: Search m => (k -> k -> k) -> (k -> k -> Ordering) -> m k -> m k ifDepth :: Search m => (Int -> Bool) -> m a -> m a -> m a diag :: Stream (Stream a) -> Stream (Bag a) class Delay m where delay = ndelay 1 ndelay n x = iterate delay x !! n delay :: Delay m => m a -> m a ndelay :: Delay m => Int -> m a -> m a getDepth :: Delay m => m Int msumMx :: Bag a -> Matrix a msumRc :: Bag a -> Recomp a listToRc :: Bag a -> Recomp a consMx :: Bag a -> Matrix a -> Matrix a consRc :: Bag a -> Recomp a -> Recomp a zipWithBF :: Monad m => (a -> b -> m c) -> m a -> m b -> m c printMx :: Show a => Matrix a -> IO () printNMx :: Show a => Int -> Matrix a -> IO () type Bag a = [a] type Stream a = [a] cat :: [[a]] -> [a] toList :: a -> a scanl1BF :: Search m => m x -> m x zipDepthMx :: (Int -> Bag a -> Bag b) -> Matrix a -> Matrix b zipDepthRc :: (Int -> Bag a -> Bag b) -> Recomp a -> Recomp b zipDepth3Mx :: (Int -> Bag a -> Bag b -> Bag c) -> Matrix a -> Matrix b -> Matrix c zipDepth3Rc :: (Int -> Bag a -> Bag b -> Bag c) -> Recomp a -> Recomp b -> Recomp c scanlRc :: (Bag a -> Bag b -> Bag a) -> Bag a -> Recomp b -> Recomp a newtype DBound a DB :: (Int -> Bag (a, Int)) -> DBound a [unDB] :: DBound a -> Int -> Bag (a, Int) newtype DBoundT m a DBT :: (Int -> m (Bag (a, Int))) -> DBoundT m a [unDBT] :: DBoundT m a -> Int -> m (Bag (a, Int)) newtype DBMemo a DBM :: Stream (Bag (a, Int)) -> DBMemo a [unDBM] :: DBMemo a -> Stream (Bag (a, Int)) class (Search n) => Memoable m n tabulate :: Memoable m n => n a -> m a applyMemo :: Memoable m n => m a -> n a shrink :: (Num t1, Ix t1) => (t -> t -> t) -> (t -> t -> Maybe Ordering) -> t1 -> [(t, t1)] -> [(t, t1)] class Search m => DB m mapDepthDB :: DB m => (Bag (a, Int) -> Bag (b, Int)) -> m a -> m b zipDepthDB :: DB m => (Int -> Bag (a, Int) -> Bag (b, Int)) -> m a -> m b dbtToRcT :: Monad m => DBoundT m a -> RecompT m a instance GHC.Show.Show a => GHC.Show.Show (Control.Monad.Search.Combinatorial.Matrix a) instance GHC.Base.Monoid (Control.Monad.Search.Combinatorial.Matrix a) instance GHC.Base.Monoid (Control.Monad.Search.Combinatorial.Recomp a) instance (GHC.Base.Functor m, GHC.Base.Monad m) => GHC.Base.Monoid (Control.Monad.Search.Combinatorial.RecompT m a) instance GHC.Base.Applicative Control.Monad.Search.Combinatorial.Matrix instance GHC.Base.Monad Control.Monad.Search.Combinatorial.Matrix instance GHC.Base.Alternative Control.Monad.Search.Combinatorial.Matrix instance GHC.Base.MonadPlus Control.Monad.Search.Combinatorial.Matrix instance GHC.Base.Functor Control.Monad.Search.Combinatorial.Matrix instance GHC.Base.Functor Control.Monad.Search.Combinatorial.Recomp instance GHC.Base.Functor Control.Monad.Search.Combinatorial.DBound instance GHC.Base.Functor f => GHC.Base.Functor (Control.Monad.Search.Combinatorial.RecompT f) instance GHC.Base.Functor f => GHC.Base.Functor (Control.Monad.Search.Combinatorial.DBoundT f) instance GHC.Base.Applicative Control.Monad.Search.Combinatorial.Recomp instance GHC.Base.Monad Control.Monad.Search.Combinatorial.Recomp instance (GHC.Base.Functor m, GHC.Base.Monad m) => GHC.Base.Applicative (Control.Monad.Search.Combinatorial.RecompT m) instance (GHC.Base.Functor m, GHC.Base.Monad m) => GHC.Base.Monad (Control.Monad.Search.Combinatorial.RecompT m) instance GHC.Base.Alternative Control.Monad.Search.Combinatorial.Recomp instance GHC.Base.MonadPlus Control.Monad.Search.Combinatorial.Recomp instance (GHC.Base.Functor m, GHC.Base.Monad m) => GHC.Base.Alternative (Control.Monad.Search.Combinatorial.RecompT m) instance (GHC.Base.Functor m, GHC.Base.Monad m) => GHC.Base.MonadPlus (Control.Monad.Search.Combinatorial.RecompT m) instance Control.Monad.Search.Combinatorial.DB Control.Monad.Search.Combinatorial.DBound instance (GHC.Base.Functor m, GHC.Base.Monad m) => Control.Monad.Search.Combinatorial.DB (Control.Monad.Search.Combinatorial.DBoundT m) instance Control.Monad.Search.Combinatorial.Delay Control.Monad.Search.Combinatorial.DepthFst instance Control.Monad.Search.Combinatorial.Delay Control.Monad.Search.Combinatorial.Recomp instance Control.Monad.Search.Combinatorial.Delay Control.Monad.Search.Combinatorial.Matrix instance GHC.Base.Monad m => Control.Monad.Search.Combinatorial.Delay (Control.Monad.Search.Combinatorial.RecompT m) instance (GHC.Base.Monad m, Control.Monad.Search.Combinatorial.Delay m) => Control.Monad.Search.Combinatorial.Delay (Control.Monad.Trans.State.Lazy.StateT s m) instance Control.Monad.Search.Combinatorial.Search Control.Monad.Search.Combinatorial.DepthFst instance Control.Monad.Search.Combinatorial.Search Control.Monad.Search.Combinatorial.Recomp instance (GHC.Base.Functor m, GHC.Base.Monad m) => Control.Monad.Search.Combinatorial.Search (Control.Monad.Search.Combinatorial.RecompT m) instance Control.Monad.Search.Combinatorial.Search Control.Monad.Search.Combinatorial.Matrix instance GHC.Show.Show (Control.Monad.Search.Combinatorial.Recomp a) instance GHC.Show.Show (Control.Monad.Search.Combinatorial.DBound a) instance GHC.Base.Applicative Control.Monad.Search.Combinatorial.DBound instance GHC.Base.Monad Control.Monad.Search.Combinatorial.DBound instance (GHC.Base.Functor m, GHC.Base.Monad m) => GHC.Base.Applicative (Control.Monad.Search.Combinatorial.DBoundT m) instance (GHC.Base.Functor m, GHC.Base.Monad m) => GHC.Base.Monad (Control.Monad.Search.Combinatorial.DBoundT m) instance GHC.Base.Alternative Control.Monad.Search.Combinatorial.DBound instance GHC.Base.MonadPlus Control.Monad.Search.Combinatorial.DBound instance (GHC.Base.Functor m, GHC.Base.Monad m) => GHC.Base.Alternative (Control.Monad.Search.Combinatorial.DBoundT m) instance (GHC.Base.Functor m, GHC.Base.Monad m) => GHC.Base.MonadPlus (Control.Monad.Search.Combinatorial.DBoundT m) instance Control.Monad.Search.Combinatorial.Delay Control.Monad.Search.Combinatorial.DBound instance GHC.Base.Monad m => Control.Monad.Search.Combinatorial.Delay (Control.Monad.Search.Combinatorial.DBoundT m) instance Control.Monad.Search.Combinatorial.Search Control.Monad.Search.Combinatorial.DBound instance (GHC.Base.Functor m, GHC.Base.Monad m) => Control.Monad.Search.Combinatorial.Search (Control.Monad.Search.Combinatorial.DBoundT m) instance Control.Monad.Search.Combinatorial.Memoable Control.Monad.Search.Combinatorial.Matrix Control.Monad.Search.Combinatorial.Recomp instance Control.Monad.Search.Combinatorial.Memoable Control.Monad.Search.Combinatorial.DBMemo Control.Monad.Search.Combinatorial.DBound module Control.Monad.Search.Best -- | Unlike Matrix, Recomp, etc., the Best monad only -- keeps the best set of results. This makes the analytical synthesis -- like IgorII, and the exhaustive synthesis like Djinn, i.e., the -- resulting algorithms are more efficient, but cannot be used for -- (analytically-)generate-and-test. data Best a Result :: [a] -> Best a Delay :: (Best a) -> Best a getBests :: Best a -> [a] zero :: Best a fromLists :: [[a]] -> Best a instance GHC.Read.Read a => GHC.Read.Read (Control.Monad.Search.Best.Best a) instance GHC.Show.Show a => GHC.Show.Show (Control.Monad.Search.Best.Best a) instance GHC.Base.Functor Control.Monad.Search.Best.Best instance GHC.Base.Applicative Control.Monad.Search.Best.Best instance GHC.Base.Monad Control.Monad.Search.Best.Best instance GHC.Base.Alternative Control.Monad.Search.Best.Best instance GHC.Base.MonadPlus Control.Monad.Search.Best.Best instance Control.Monad.Search.Combinatorial.Delay Control.Monad.Search.Best.Best instance Control.Monad.Search.Combinatorial.Search Control.Monad.Search.Best.Best instance Control.Monad.Search.Combinatorial.Memoable Control.Monad.Search.Best.Best Control.Monad.Search.Best.Best module MagicHaskeller.Options -- | options that limit the hypothesis space. data Opt a Opt :: Maybe a -> Int -> (Type -> Int -> Bool) -> MemoCond -> (VarLib -> CoreExpr -> Dynamic) -> Maybe Int -> Bool -> Bool -> Bool -> Bool -> Int -> Bool -> Bool -> StdGen -> [Int] -> (Int -> Int) -> Opt a -- | Use this option if you want to use a different component library for -- the stage of solving the inhabitation problem. Nothing means -- using the same one. This option makes sense only when using *SF style -- generators, because otherwise the program generation is not staged. -- Using a minimal set for solving the inhabitation and a redundant -- library for the real program generation can be a good bet. [primopt] :: Opt a -> Maybe a -- | memoization depth. (Sub)expressions within this size are memoized, -- while greater expressions will be recomputed (to save the heap space). -- Only effective when using ProgGen and unless using the -- everythingIO family. [memodepth] :: Opt a -> Int -- | This represents when to memoize. It takes the query type and the query -- depth, and returns True if the corresponding entry should be -- looked up from the lazy memo table. Currently this only works for -- ProgGenSF. [memoCondPure] :: Opt a -> Type -> Int -> Bool -- | This represents which memoization table to be used based on the query -- type and the search depth, when using the everythingIO -- family. [memoCond] :: Opt a -> MemoCond [execute] :: Opt a -> VarLib -> CoreExpr -> Dynamic -- | Just ms sets the timeout to ms microseconds. Also, -- my implementation of timeout also catches inevitable exceptions like -- stack space overflow. Note that setting timeout makes the library -- referentially untransparent. (But currently Just 20000 is the -- default!) Setting this option to Nothing disables both -- timeout and capturing exceptions. [timeout] :: Opt a -> Maybe Int -- | If this option is True, forkProcess instead of -- forkIO is used for timeout. The former is much heavier than the -- latter, but is more preemptive and thus is necessary for interrupting -- some infinite loops. This record is ignored if FORCIBLETO is not -- defined. [forcibleTimeout] :: Opt a -> Bool -- | If this option is True, the program guesses whether each -- function is a casecatamorphismparamorphism or not. This -- information is used to filter out some duplicate expressions. -- (History: I once abandoned this guessing strategy around the time I -- moved to the library implementation, because I could not formally -- prove the exhaustiveness of the resulting algorithm. For this reason, -- the old standalone version of MagicHaskeller uses this strategy, but -- almost the same effect can be obtained by setting this option to True, -- or using init075 instead of initialize. [guess] :: Opt a -> Bool -- | This option is now obsolete, and we always assume True now. If this -- option was False, data structures might not contain -- functions, and thus types like [Int->Int], -- (Int->Bool, Char), etc. were not permitted. (NB: recently -- I noticed that making this False might not improve the -- efficiency of generating lambda terms at all, though when I generated -- combinatory expressions it WAS necessary. In fact, I mistakenly turned -- this limitation off, and my code always regarded this as True, but I -- did not notice that, so this option can be obsoleted.) [contain] :: Opt a -> Bool -- | If this option is True, matching at the antecedent of -- induction rules may occur, which constrains generation of existential -- types. You need to use prefixed (->) to show that some -- parameter can be matched at the antecedent, e.g., p [| ( -- []::[a], (:)::a->[a]->[a], foldr :: (a->b->b) -> b -- -> (->) [a] b ) |] See LibTH.hs for examples. [constrL] :: Opt a -> Bool -- | Each time the type variable which appears in the return type of a -- function (e.g. b in -- foldr::(a->b->b)->b->[a]->b) is expanded to a -- function type, the search priority of the current computation is -- lowered by this number. It's default value is 1, which means there is -- nothing special, and the priority for each expression corresponds to -- the number of function applications in the expression. -- -- Example: when tvndelay = 1, -- -- The priority of -- --
-- \xs -> foldr (\x y -> x+y) 0 xs ---- -- is 5, because there are five $'s in -- --
-- \xs -> ((foldr $ (\x y -> ((+) $ x) $ y)) $ 0) xs ---- -- The priority of -- --
-- \xs ys -> foldr (\x y zs -> x : y zs) (\ws->ws) xs ys ---- -- is 7, because there are seven $'s in -- --
-- \xs ys -> (((foldr $ (\x y zs -> (((:) $ x) $ y) $ zs)) $ (\ws->ws)) $ xs) $ ys ---- -- Example: when tvndelay = 2, -- -- The priority of -- --
-- \xs -> foldr (\x y -> x+y) 0 xs ---- -- is 5, because there are five $'s in -- --
-- \xs -> ((foldr $ (\x y -> ((+) $ x) $ y)) $ 0) xs ---- -- The priority of -- --
-- \xs ys -> foldr (\x y zs -> x : y zs) (\ws->ws) xs ys ---- -- is 8, because there are eight $'s in -- --
-- \xs ys -> (((foldr $ (\x y zs -> (((:) $ x) $ y) $ zs)) $ (\ws->ws)) $ xs) $$ ys ---- -- where $$ denotes the function application caused by expanding -- a type variable into a function type. [tvndelay] :: Opt a -> Int -- | If this option is True, the return type of functions -- returning a type variable (e.g. b in -- foldr::(a->b->b)->b->[a]->b) can only be -- replaced with Eval t => t and Eval t => u -> -- t, while if False with Eval t => t, Eval -- t => u->t, Eval t => u->v->t, etc., where -- Eval t means t cannot be replaced with a function. The -- restriction can be amended if the tuple constructor and destructors -- are available. [tv1] :: Opt a -> Bool [tv0] :: Opt a -> Bool -- | The random seed. [stdgen] :: Opt a -> StdGen -- | number of random samples at each depth, for each type, for the filter -- applied during synthesis (used by ProgGenSF, &c.). [nrands] :: Opt a -> [Int] -- | number of random samples at each depth, for each type, for the filter -- applied after synthesis (used by filterThenF, &c.). [fcnrand] :: Opt a -> Int -> Int -- | default options -- --
-- options = Opt{ primopt = Nothing
-- , memodepth = 10
-- , memoCondPure = \ _type depth -> 0<depth
-- , memoCond = \ _type depth -> return $ if depth < 10 then Ram else Recompute
-- , execute = unsafeExecute
-- , timeout = Just 20000
-- , forcibleTimeout = False
-- , guess = False
-- , contain = True
-- , constrL = False
-- , tv1 = False
--
options :: Opt a
forget :: Opt a -> Opt ()
nrnds :: [Int]
chopRnds :: [[a]] -> [[a]]
fnrnds :: Num a => t -> a
module MagicHaskeller.Classification
class (Search m) => SStrategy m
sfilter :: (SStrategy m, Relation r) => (k -> k -> r) -> (Int -> Int) -> m ([k], e) -> m ([k], e)
ofilter :: (SStrategy m, Relation r) => (k -> k -> r) -> m (k, e) -> m (k, e)
arbitraries :: Arbitrary a => [a]
arbs :: Arbitrary a => Int -> StdGen -> [a]
(/~) :: [a] -> (a -> a -> Bool) -> [[a]]
nubSortBy :: (a -> a -> Ordering) -> [a] -> [a]
nubSortByBot :: (a -> a -> Maybe Ordering) -> [a] -> [a]
(/<) :: [a] -> (a -> a -> Ordering) -> [[a]]
(/) :: [a] -> (a -> a -> Maybe Ordering) -> [[a]]
class Eq rel => Relation rel where fromListBy cmp = map head . (/ cmp) fromListByDB rel ts = map (minimumBy (\ x y -> compare (snd y) (snd x))) (ts / (\ x y -> rel (fst x) (fst y)))
fromListBy :: Relation rel => (k -> k -> rel) -> [k] -> [k]
fromListByDB :: Relation rel => (k -> k -> rel) -> [(k, Int)] -> [(k, Int)]
(/) :: Relation rel => [k] -> (k -> k -> rel) -> [[k]]
appendWithBy :: Relation rel => (k -> k -> k) -> (k -> k -> rel) -> [k] -> [k] -> [k]
diffBy :: Relation rel => (k -> k -> rel) -> [k] -> [k] -> [k]
cEQ :: Relation rel => rel
appendQuotientsBy :: (Relation rel) => (k -> k -> rel) -> [[k]] -> [[k]] -> [[k]]
appendRepresentativesBy :: (Relation rel) => (k -> k -> rel) -> [k] -> [k] -> [k]
unionWithBy :: (a -> a -> a) -> (a -> a -> Bool) -> [a] -> [a] -> [a]
randomTestFilter :: (SStrategy m, Filtrable a) => (Int -> Int) -> m (e, a) -> m (e, a)
unsafeRandomTestFilter :: (SStrategy m, Filtrable a) => Maybe Int -> (Int -> Int) -> m (e, a) -> m (e, a)
mapFst :: (t -> t1) -> (t, t2) -> (t1, t2)
class Filtrable a
filt :: (Filtrable a, SStrategy m) => (Int -> Int) -> m (a, e) -> m e
filtFun :: (Filtrable a, SStrategy m, Arbitrary b) => (Int -> Int) -> m (b -> a, e) -> m e
unsafeFilt :: (Filtrable a, SStrategy m) => Maybe Int -> (Int -> Int) -> m (a, e) -> m e
unsafeFiltFun :: (Filtrable a, SStrategy m, Arbitrary b) => Maybe Int -> (Int -> Int) -> m (b -> a, e) -> m e
filtNullary :: (SStrategy m, Relation r) => (k -> k -> r) -> (Int -> Int) -> m (k, e) -> m e
filtUnary :: (Arbitrary a, Relation r, SStrategy f) => (k -> k -> r) -> (Int -> Int) -> f (a -> k, b) -> f b
compareCx :: (RealFloat a, Ord a) => Complex a -> Complex a -> Ordering
ofilterMx :: Relation r => (k -> k -> r) -> Matrix (k, e) -> Matrix (k, e)
ofilterDB :: Relation rel => (k -> k -> rel) -> DBound (k, e) -> DBound (k, e)
cumulativeRepresentatives :: Relation rel => [a -> a -> rel] -> Matrix a -> Matrix a
representatives :: Relation rel => [a -> a -> rel] -> Matrix a -> Matrix a
unscanlByList :: Relation r => [k -> k -> r] -> Matrix k -> Matrix k
sfilterMx :: Relation r => (k -> k -> r) -> (Int -> Int) -> Matrix ([k], e) -> Matrix ([k], e)
liftRelation :: Relation r => (k -> k -> r) -> Int -> ([k], e) -> ([k], e) -> r
liftRel :: (Eq a, Num a, Relation rel) => (t -> t1 -> rel) -> a -> [t] -> [t1] -> rel
sfilterDB :: Relation rel => (k -> k -> rel) -> (Int -> Int) -> DBound ([k], e) -> DBound ([k], e)
cumulativeQuotients :: Relation rel => [k -> k -> rel] -> Matrix k -> Matrix [k]
ns :: [Integer]
instance MagicHaskeller.Classification.SStrategy Control.Monad.Search.Combinatorial.Matrix
instance MagicHaskeller.Classification.SStrategy Control.Monad.Search.Combinatorial.DBound
instance MagicHaskeller.Classification.Relation GHC.Types.Bool
instance MagicHaskeller.Classification.Relation GHC.Types.Ordering
instance MagicHaskeller.Classification.Relation (GHC.Base.Maybe GHC.Types.Ordering)
instance (MagicHaskeller.MyCheck.Arbitrary a, MagicHaskeller.Classification.Filtrable r) => MagicHaskeller.Classification.Filtrable (a -> r)
instance GHC.Classes.Ord a => MagicHaskeller.Classification.Filtrable a
instance MagicHaskeller.Classification.Filtrable GHC.Types.Double
instance (GHC.Float.RealFloat a, GHC.Classes.Ord a) => MagicHaskeller.Classification.Filtrable (Data.Complex.Complex a)
module MagicHaskeller.Expression
data AnnExpr
AE :: CoreExpr -> Dynamic -> AnnExpr
data MemoExpr
ME :: CoreExpr -> Dynamic -> Dynamic -> MemoExpr
aeToME :: TyConLib -> RTrie -> Type -> AnnExpr -> MemoExpr
meToAE :: MemoExpr -> AnnExpr
class (Ord e, Show e) => Expression e where reorganizeId' fun avail = case cvtAvails' avail of { (args, newavail) -> fmap (\ e -> replaceVars' 0 e args) $ fun newavail }
mkHead :: (Expression e, Integral i, Integral j) => (CoreExpr -> Dynamic) -> i -> j -> CoreExpr -> e
toCE :: Expression e => e -> CoreExpr
fromCE :: Expression e => (CoreExpr -> Dynamic) -> CoreExpr -> e
mapCE :: Expression e => (CoreExpr -> CoreExpr) -> e -> e
aeAppErr :: Expression e => String -> e -> e -> e
appEnv :: Expression e => Int8 -> e -> e -> e
toAnnExpr :: Expression e => (CoreExpr -> Dynamic) -> e -> AnnExpr
toAnnExprWind :: Expression e => (CoreExpr -> Dynamic) -> Type -> e -> AnnExpr
toAnnExprWindWind :: Expression e => (CoreExpr -> Dynamic) -> Type -> e -> AnnExpr
fromAnnExpr :: Expression e => AnnExpr -> e
reorganize :: (Expression e, Monad m) => ([Type] -> m [e]) -> [Type] -> m [e]
reorganize' :: (Expression e, Monad m) => ([Type] -> m [e]) -> [Type] -> m [e]
reorganizeId :: Expression e => ([Type] -> [e]) -> [Type] -> [e]
replaceVars' :: Expression e => Int8 -> e -> [Int8] -> e
reorganizeId' :: (Expression e, Functor m) => ([Type] -> m e) -> [Type] -> m e
(<$>) :: Expression e => e -> e -> e
mkHeadAE :: (CoreExpr -> Dynamic) -> Int8 -> Int8 -> CoreExpr -> AnnExpr
windType :: Type -> CoreExpr -> CoreExpr
dynSn :: Int8 -> Dynamic
getDyn :: Int8 -> Int8 -> Dynamic
mkDyn :: Int8 -> Int8 -> Dynamic
dynss :: [[Dynamic]]
x :: Integral i => i -> Dynamic
finiteDynar :: Array (Int8, Int8) Dynamic
finiteDynarr :: Array (Int8, Int8, Int8) Dynamic
finiteDynss :: [[Dynamic]]
finiteDynsss :: [[[Dynamic]]]
getDyn_LambdaBoundHead :: Int8 -> Int8 -> Int8 -> Dynamic
mkDyn_LambdaBoundHead :: Int8 -> Int8 -> Int8 -> Dynamic
dynsss :: [[[Dynamic]]]
dynBK :: Dynamic
reorganizer :: Monad m => ([Type] -> m [CoreExpr]) -> [Type] -> m [CoreExpr]
reorganizerId :: ([Type] -> [CoreExpr]) -> [Type] -> [CoreExpr]
replaceVars :: Int8 -> CoreExpr -> [[Int8]] -> [CoreExpr]
cvtAvails :: [Type] -> ([Type], [[Int8]])
tkr10 :: [(Type, a)] -> [(Type, [a])]
annotate :: [Type] -> [(Type, Int8)]
reorganizeCE' :: Monad m => ([Type] -> m [CoreExpr]) -> [Type] -> m [CoreExpr]
replaceVarsCE' :: Int8 -> CoreExpr -> [Int8] -> CoreExpr
cvtAvails' :: [Type] -> ([Int8], [Type])
uniqSorter :: (Expression e) => [(e, Int)] -> [(e, Int)]
uniqSortPatAVL :: (Expression e) => [(e, Int)] -> [(e, Int)]
uniqSort :: Ord a => [a] -> [a]
uniqSortAVL :: Ord a => [a] -> [a]
swapUniqSort :: (Ord a, Ord b) => [(a, b)] -> [(a, b)]
see :: Int8 -> Int8 -> String
seeType :: Int8 -> Int8 -> CoreExpr
sees :: Int8 -> Int8 -> Int8 -> String
seesType :: Int8 -> Int8 -> Int8 -> CoreExpr
e2THE :: CoreExpr -> Exp
printTables :: IO ()
printTable :: IO ()
pprintType :: Type -> String
mkVName :: Char -> Int -> Q Name
mkVNames :: Char -> Int -> Q [Name]
mkEs :: Int -> Q [Name]
mkAs :: Int -> Q [Name]
mkXs :: Int -> Q [Name]
mkHd :: Q Name
hdmnTHEQ :: Int8 -> Int8 -> ExpQ
aimnTHEQ :: Int8 -> Int8 -> Int8 -> ExpQ
hdmnTHE :: Int8 -> Int8 -> Exp
aimnTHE :: Int8 -> Int8 -> Int8 -> Exp
hdmnty :: Int8 -> Int8 -> Type
aimnty :: Int8 -> Int8 -> Int8 -> Type
mkTV :: TyVar -> Type
tvrs :: [Type]
tvas :: [Type]
tvr :: Type
maxArity :: Int8
maxLenavails :: Int8
maxDebindex :: Int8
mkCE :: Int8 -> Int8 -> CoreExpr
mkCE_LambdaBoundHead :: Int8 -> Int8 -> Int8 -> CoreExpr
data CoreExpr
instance GHC.Show.Show MagicHaskeller.Expression.AnnExpr
instance GHC.Classes.Eq MagicHaskeller.Expression.AnnExpr
instance GHC.Classes.Ord MagicHaskeller.Expression.AnnExpr
instance MagicHaskeller.Expression.Expression MagicHaskeller.CoreLang.CoreExpr
instance MagicHaskeller.Expression.Expression MagicHaskeller.Expression.AnnExpr
module MagicHaskeller.ProgGen
-- | The vanilla program generator corresponding to Version 0.7.*
newtype ProgGen
-- | internal data representation
PG :: (MemoDeb (ClassLib CoreExpr) CoreExpr) -> ProgGen
mkCL :: Common -> [Typed [CoreExpr]] -> ClassLib CoreExpr
newtype ClassLib e
CL :: (MemoDeb (ClassLib e) e) -> ClassLib e
mguPrograms :: (Search m) => Generator m CoreExpr
instance MagicHaskeller.ProgramGenerator.WithCommon MagicHaskeller.ProgGen.ProgGen
instance MagicHaskeller.ProgramGenerator.ProgramGenerator MagicHaskeller.ProgGen.ProgGen
instance MagicHaskeller.ProgramGenerator.ProgramGeneratorIO MagicHaskeller.ProgGen.ProgGen
module MagicHaskeller.ProgGenSF
type ProgGenSF = PGSF CoreExpr
-- | Program generator with synergetic filtration. This program generator
-- employs filtration by random testing, and rarely generate semantically
-- equivalent expressions more than once, while different expressions
-- will eventually appear (for most of the types, represented with
-- Prelude types, whose arguments are instance of Arbitrary and which
-- return instance of Ord). The idea is to apply random numbers to the
-- generated expressions, compute the quotient set of the resulting
-- values at each depth of the search tree, and adopt the complete system
-- of representatives for the depth and push the remaining expressions to
-- one step deeper in the search tree. (Thus, adoption of expressions
-- that may be equivalent to another already-generated-expression will be
-- postponed until their "uniqueness" is proved.) As a result, (unlike
-- ProgGen,) expressions with size N may not appear at depth N but
-- some deeper place.
--
-- ProgGenSF is more efficient along with a middle-sized primitive
-- set (like reallyall found in LibTH.hs), but is slower than
-- ProgGen for a small-sized one.
--
-- Also note that ProgGenSF depends on hard use of unsafe* stuff,
-- so if there is a bug, it may segfault....
data PGSF e
PGSF :: (MemoDeb e) -> TypeTrie -> (ExpTrie e) -> PGSF e
freezePS :: Type -> PriorSubsts Recomp Type -> Matrix (Type, Subst, TyVar)
funApSub_ :: (Search m, Monoid a) => (Type -> PriorSubsts m ()) -> (Type -> PriorSubsts m a) -> (Type -> PriorSubsts m a) -> Type -> PriorSubsts m a
funApSub_spec :: (Monoid a, Search m) => (Type -> PriorSubsts m ()) -> (Type -> PriorSubsts m a) -> Type -> PriorSubsts m a
lookupNormalized :: (Functor m, MonadPlus m) => (Type -> m (e, Subst, TyVar)) -> [Type] -> Type -> PriorSubsts m e
tokoro10fst :: (Eq k, Ord k) => [(k, s, i)] -> [(k, s, i)]
mkTrieOptSFIO :: Common -> [Typed [CoreExpr]] -> [[Typed [CoreExpr]]] -> [[Typed [CoreExpr]]] -> IO (PGSF CoreExpr)
instance MagicHaskeller.ProgramGenerator.ProgramGenerator (MagicHaskeller.ProgGenSF.PGSF MagicHaskeller.CoreLang.CoreExpr)
instance MagicHaskeller.Expression.Expression e => MagicHaskeller.ProgramGenerator.WithCommon (MagicHaskeller.ProgGenSF.PGSF e)
instance GHC.Base.Monoid MagicHaskeller.ProgGenSF.BitSet
module MagicHaskeller.ProgGenSFIORef
type ProgGenSFIORef = PGSFIOR CoreExpr
-- | Program generator with synergetic filtration. This program generator
-- employs filtration by random testing, and rarely generate semantically
-- equivalent expressions more than once, while different expressions
-- will eventually appear (for most of the types, represented with
-- Prelude types, whose arguments are instance of Arbitrary and which
-- return instance of Ord). The idea is to apply random numbers to the
-- generated expressions, compute the quotient set of the resulting
-- values at each depth of the search tree, and adopt the complete system
-- of representatives for the depth and push the remaining expressions to
-- one step deeper in the search tree. (Thus, adoption of expressions
-- that may be equivalent to another already-generated-expression will be
-- postponed until their "uniqueness" is proved.) As a result, (unlike
-- ProgGen,) expressions with size N may not appear at depth N but
-- some deeper place.
--
-- ProgGenSF is more efficient along with a middle-sized primitive
-- set (like reallyall found in LibTH.hs), but is slower than
-- ProgGen for a small-sized one.
--
-- Also note that ProgGenSF depends on hard use of unsafe* stuff,
-- so if there is a bug, it may segfault....
data PGSFIOR e
instance MagicHaskeller.ProgramGenerator.ProgramGeneratorIO (MagicHaskeller.ProgGenSFIORef.PGSFIOR MagicHaskeller.CoreLang.CoreExpr)
instance MagicHaskeller.Expression.Expression e => MagicHaskeller.ProgramGenerator.WithCommon (MagicHaskeller.ProgGenSFIORef.PGSFIOR e)
module MagicHaskeller.ExecuteAPI610
pathToGHC :: FilePath
loadObj :: [String] -> IO (VarLib -> CoreExpr -> Dynamic)
prepareAPI :: [FilePath] -> [FilePath] -> IO HscEnv
packageNameToFlag :: String -> PackageFlag
unsafeExecuteAPI :: HscEnv -> VarLib -> CoreExpr -> Dynamic
executeAPI :: HscEnv -> VarLib -> CoreExpr -> IO a
executeTHExp :: HscEnv -> Exp -> IO a
compileCoreExpr :: HscEnv -> Exp -> IO CoreExpr
unwrapCore :: HscEnv -> CoreExpr -> IO a
ce2b :: DynFlags -> CoreExpr -> IO UnlinkedBCO
runCoreExpr :: HscEnv -> CoreExpr -> IO a
runPrepedCoreExpr :: HscEnv -> CoreExpr -> IO a
stmtToCore :: HscEnv -> GhciLStmt RdrName -> IO (Maybe ([Id], CoreExpr))
perror :: DynFlags -> (Bag ErrMsg, Bag ErrMsg) -> IO (Maybe a)
thExpToStmt :: HscEnv -> Exp -> Located (StmtLR RdrName RdrName body)
wrapLHsExpr :: LHsExpr RdrName -> Located (StmtLR RdrName RdrName body)
thExpToLHsExpr :: HscEnv -> Exp -> LHsExpr RdrName
compileExprHscMain :: HscEnv -> CoreExpr -> IO HValue
repeatN :: Int -> (a1 -> a) -> a1 -> a
repeatIO :: Monad f => Int -> f b -> f b
force :: [a] -> a
instance GHC.Classes.Eq (CoreSyn.Expr a)
module MagicHaskeller
-- | ProgramGenerator is a generalization of the old Memo type.
class WithCommon a => ProgramGenerator a where mkTrie cmn c t = mkTrieOpt cmn c t t mkTrieOpt cmn c _ t = mkTrie cmn c t matchingPrograms ty memodeb = unifyingPrograms (quantify ty) memodeb matchingProgramsWOAbsents ty memodeb = mapDepth (filter (not . isAbsent (getArity ty) . toCE)) $ matchingPrograms ty memodeb
-- | The vanilla program generator corresponding to Version 0.7.*
data ProgGen
type ProgGenSF = PGSF CoreExpr
type ProgGenSFIORef = PGSFIOR CoreExpr
-- | p is used to convert your primitive component set into the
-- internal form.
p :: ExpQ -> ExpQ
-- | setPrimitives creates a ProgGen from the given set
-- of primitives using the current set of options, and sets it as the
-- current program generator. It used to be equivalent to setPG .
-- mkPG which overwrites the options with the default, but it is not
-- now.
setPrimitives :: [Primitive] -> [Primitive] -> IO ()
mkPG :: ProgramGenerator pg => [Primitive] -> pg
-- | mkPGSF and mkMemoSF are provided mainly for backward
-- compatibility. These functions are defined only for the
-- ProgramGenerators whose names end with SF (i.e.,
-- generators with synergetic filtration). For such generators, they are
-- defined as:
--
--
-- mkPGSF gen nrnds optups tups = mkPGOpt (options{primopt = Just optups, contain = True, stdgen = gen, nrands = nrnds}) tups
-- mkMemoSF gen nrnds optups tups = mkPGOpt (options{primopt = Just optups, contain = False, stdgen = gen, nrands = nrnds}) tups
--
mkPGSF :: ProgramGenerator pg => StdGen -> [Int] -> [Primitive] -> [Primitive] -> [Primitive] -> pg
setPG :: ProgGen -> IO ()
mkMemo :: ProgramGenerator pg => [Primitive] -> pg
-- | mkPGSF and mkMemoSF are provided mainly for backward
-- compatibility. These functions are defined only for the
-- ProgramGenerators whose names end with SF (i.e.,
-- generators with synergetic filtration). For such generators, they are
-- defined as:
--
--
-- mkPGSF gen nrnds optups tups = mkPGOpt (options{primopt = Just optups, contain = True, stdgen = gen, nrands = nrnds}) tups
-- mkMemoSF gen nrnds optups tups = mkPGOpt (options{primopt = Just optups, contain = False, stdgen = gen, nrands = nrnds}) tups
--
mkMemoSF :: ProgramGenerator pg => StdGen -> [Int] -> [Primitive] -> [Primitive] -> [Primitive] -> pg
mkPG075 :: ProgramGenerator pg => [Primitive] -> [Primitive] -> pg
mkMemo075 :: ProgramGenerator pg => [Primitive] -> [Primitive] -> pg
mkPGOpt :: ProgramGenerator pg => Options -> [Primitive] -> [Primitive] -> pg
-- | mkPG is defined as:
--
-- -- mkPG prims = mkPGSF (mkStdGen 123456) (repeat 5) prims prims --mkPGX :: ProgramGenerator pg => [Primitive] -> [[Primitive]] -> pg mkPGXOpt :: ProgramGenerator pg => Options -> [Primitive] -> [(Primitive, Primitive)] -> [[Primitive]] -> [[(Primitive, Primitive)]] -> pg mkPGXOpts :: (Common -> [Typed [CoreExpr]] -> [[Typed [CoreExpr]]] -> [[Typed [CoreExpr]]] -> t) -> Options -> [Primitive] -> [(Primitive, Primitive)] -> [[Primitive]] -> [[(Primitive, Primitive)]] -> t -- | options for limiting the hypothesis space. type Options = Opt [[Primitive]] -- | options that limit the hypothesis space. data Opt a Opt :: Maybe a -> Int -> (Type -> Int -> Bool) -> MemoCond -> (VarLib -> CoreExpr -> Dynamic) -> Maybe Int -> Bool -> Bool -> Bool -> Bool -> Int -> Bool -> Bool -> StdGen -> [Int] -> (Int -> Int) -> Opt a -- | Use this option if you want to use a different component library for -- the stage of solving the inhabitation problem. Nothing means -- using the same one. This option makes sense only when using *SF style -- generators, because otherwise the program generation is not staged. -- Using a minimal set for solving the inhabitation and a redundant -- library for the real program generation can be a good bet. [primopt] :: Opt a -> Maybe a -- | memoization depth. (Sub)expressions within this size are memoized, -- while greater expressions will be recomputed (to save the heap space). -- Only effective when using ProgGen and unless using the -- everythingIO family. [memodepth] :: Opt a -> Int -- | This represents when to memoize. It takes the query type and the query -- depth, and returns True if the corresponding entry should be -- looked up from the lazy memo table. Currently this only works for -- ProgGenSF. [memoCondPure] :: Opt a -> Type -> Int -> Bool -- | This represents which memoization table to be used based on the query -- type and the search depth, when using the everythingIO -- family. [memoCond] :: Opt a -> MemoCond [execute] :: Opt a -> VarLib -> CoreExpr -> Dynamic -- | Just ms sets the timeout to ms microseconds. Also, -- my implementation of timeout also catches inevitable exceptions like -- stack space overflow. Note that setting timeout makes the library -- referentially untransparent. (But currently Just 20000 is the -- default!) Setting this option to Nothing disables both -- timeout and capturing exceptions. [timeout] :: Opt a -> Maybe Int -- | If this option is True, forkProcess instead of -- forkIO is used for timeout. The former is much heavier than the -- latter, but is more preemptive and thus is necessary for interrupting -- some infinite loops. This record is ignored if FORCIBLETO is not -- defined. [forcibleTimeout] :: Opt a -> Bool -- | If this option is True, the program guesses whether each -- function is a casecatamorphismparamorphism or not. This -- information is used to filter out some duplicate expressions. -- (History: I once abandoned this guessing strategy around the time I -- moved to the library implementation, because I could not formally -- prove the exhaustiveness of the resulting algorithm. For this reason, -- the old standalone version of MagicHaskeller uses this strategy, but -- almost the same effect can be obtained by setting this option to True, -- or using init075 instead of initialize. [guess] :: Opt a -> Bool -- | This option is now obsolete, and we always assume True now. If this -- option was False, data structures might not contain -- functions, and thus types like [Int->Int], -- (Int->Bool, Char), etc. were not permitted. (NB: recently -- I noticed that making this False might not improve the -- efficiency of generating lambda terms at all, though when I generated -- combinatory expressions it WAS necessary. In fact, I mistakenly turned -- this limitation off, and my code always regarded this as True, but I -- did not notice that, so this option can be obsoleted.) [contain] :: Opt a -> Bool -- | If this option is True, matching at the antecedent of -- induction rules may occur, which constrains generation of existential -- types. You need to use prefixed (->) to show that some -- parameter can be matched at the antecedent, e.g., p [| ( -- []::[a], (:)::a->[a]->[a], foldr :: (a->b->b) -> b -- -> (->) [a] b ) |] See LibTH.hs for examples. [constrL] :: Opt a -> Bool -- | Each time the type variable which appears in the return type of a -- function (e.g. b in -- foldr::(a->b->b)->b->[a]->b) is expanded to a -- function type, the search priority of the current computation is -- lowered by this number. It's default value is 1, which means there is -- nothing special, and the priority for each expression corresponds to -- the number of function applications in the expression. -- -- Example: when tvndelay = 1, -- -- The priority of -- --
-- \xs -> foldr (\x y -> x+y) 0 xs ---- -- is 5, because there are five $'s in -- --
-- \xs -> ((foldr $ (\x y -> ((+) $ x) $ y)) $ 0) xs ---- -- The priority of -- --
-- \xs ys -> foldr (\x y zs -> x : y zs) (\ws->ws) xs ys ---- -- is 7, because there are seven $'s in -- --
-- \xs ys -> (((foldr $ (\x y zs -> (((:) $ x) $ y) $ zs)) $ (\ws->ws)) $ xs) $ ys ---- -- Example: when tvndelay = 2, -- -- The priority of -- --
-- \xs -> foldr (\x y -> x+y) 0 xs ---- -- is 5, because there are five $'s in -- --
-- \xs -> ((foldr $ (\x y -> ((+) $ x) $ y)) $ 0) xs ---- -- The priority of -- --
-- \xs ys -> foldr (\x y zs -> x : y zs) (\ws->ws) xs ys ---- -- is 8, because there are eight $'s in -- --
-- \xs ys -> (((foldr $ (\x y zs -> (((:) $ x) $ y) $ zs)) $ (\ws->ws)) $ xs) $$ ys ---- -- where $$ denotes the function application caused by expanding -- a type variable into a function type. [tvndelay] :: Opt a -> Int -- | If this option is True, the return type of functions -- returning a type variable (e.g. b in -- foldr::(a->b->b)->b->[a]->b) can only be -- replaced with Eval t => t and Eval t => u -> -- t, while if False with Eval t => t, Eval -- t => u->t, Eval t => u->v->t, etc., where -- Eval t means t cannot be replaced with a function. The -- restriction can be amended if the tuple constructor and destructors -- are available. [tv1] :: Opt a -> Bool [tv0] :: Opt a -> Bool -- | The random seed. [stdgen] :: Opt a -> StdGen -- | number of random samples at each depth, for each type, for the filter -- applied during synthesis (used by ProgGenSF, &c.). [nrands] :: Opt a -> [Int] -- | number of random samples at each depth, for each type, for the filter -- applied after synthesis (used by filterThenF, &c.). [fcnrand] :: Opt a -> Int -> Int -- | default options -- --
-- options = Opt{ primopt = Nothing
-- , memodepth = 10
-- , memoCondPure = \ _type depth -> 0<depth
-- , memoCond = \ _type depth -> return $ if depth < 10 then Ram else Recompute
-- , execute = unsafeExecute
-- , timeout = Just 20000
-- , forcibleTimeout = False
-- , guess = False
-- , contain = True
-- , constrL = False
-- , tv1 = False
--
options :: Opt a
data MemoType
-- | Recompute instead of memoizing.
Recompute :: MemoType
-- | Use the memoization table based on lazy evaluation, like in older
-- versions.
Ram :: MemoType
-- | Use the directory specified by FilePath as the persistent
-- memoization table.
Disk :: FilePath -> MemoType
mkPGIO :: ProgramGeneratorIO pg => [Primitive] -> [Primitive] -> IO pg
mkPGXOptIO :: ProgramGeneratorIO pg => Options -> [Primitive] -> [(Primitive, Primitive)] -> [[Primitive]] -> [[(Primitive, Primitive)]] -> IO pg
-- | load loads a component library file.
load :: FilePath -> ExpQ
-- | f is supposed to be used by load, but not hidden.
f :: String -> ExpQ
-- | Currently the default depth is 10. You may want to lower the value if
-- your computer often swaps, or increase it if you have a lot of memory.
setDepth :: Int -> IO ()
-- | setTimeout sets the timeout in microseconds. Also, my
-- implementation of timeout also catches inevitable exceptions like
-- stack space overflow. Note that setting timeout makes the library
-- referentially untransparent. (But currently setTimeout 20000
-- is the default!)
setTimeout :: Int -> IO ()
-- | unsetTimeout disables timeout. This is the safe choice.
unsetTimeout :: IO ()
-- | define eases use of this library by automating some function
-- definitions. For example,
--
-- -- $( define ''ProgGen "Foo" (p [| (1 :: Int, (+) :: Int -> Int -> Int) |]) ) ---- -- is equivalent to -- --
-- memoFoo :: ProgGen -- memoFoo = mkPG (p [| (1 :: Int, (+) :: Int -> Int -> Int) |]) -- everyFoo :: Everything -- everyFoo = everything memoFoo -- filterFoo :: Filter -- filterFoo pred = filterThen pred everyFoo ---- -- If you do not think this function reduces the number of your -- keystrokes a lot, you can do without it. define :: Name -> String -> ExpQ -> Q [Dec] type Everything = forall a. Typeable a => Every a type Filter = forall a. Typeable a => (a -> Bool) -> IO (Every a) type Every a = [[(Exp, a)]] type EveryIO a = Int -> IO [(Exp, a)] -- | findOne pred finds an expression e that -- satisfies pred e == True, and returns it in Exp. findOne :: Typeable a => Bool -> (a -> Bool) -> Exp -- | printOne prints the expression found first. printOne :: Typeable a => Bool -> (a -> Bool) -> IO Exp -- | printAll prints all the expressions satisfying the given -- predicate. printAll :: Typeable a => Bool -> (a -> Bool) -> IO () printAllF :: (Typeable a, Filtrable a) => Bool -> (a -> Bool) -> IO () -- | io2pred converts a specification given as a set of I/O pairs -- to the predicate form which other functions accept. io2pred :: Eq b => [(a, b)] -> ((a -> b) -> Bool) -- | filterFirst is like printAll, but by itself it does not -- print anything. Instead, it creates a stream of expressions -- represented in tuples of Exp and the expressions themselves. filterFirst :: Typeable a => Bool -> (a -> Bool) -> IO (Every a) filterFirstF :: (Typeable a, Filtrable a) => Bool -> (a -> Bool) -> IO (Every a) -- | filterThen may be used to further filter the results. filterThen :: Typeable a => (a -> Bool) -> Every a -> IO (Every a) filterThenF :: (Typeable * a, Filtrable a) => (a -> Bool) -> Every a -> IO (Every a) fp :: Typeable a => Maybe Int -> (a -> Bool) -> [(Exp, a)] -> [(Exp, a)] -- | getEverything uses the 'global' values set with set* -- functions. getEverythingF is its filtered version getEverything :: Typeable a => Bool -> IO (Every a) -- | everything generates all the expressions that fit the inferred -- type, and their representations in the Exp form. It returns a -- stream of lists, which is equivalent to Spivey's Matrix data -- type, i.e., that contains expressions consisted of n primitive -- components at the n-th element (n = 1,2,...). everythingF is -- its filtered version everything :: (ProgramGenerator pg, Typeable a) => pg -> Bool -> Every a everythingM :: (ProgramGenerator pg, Typeable a, Monad m, Functor m) => pg -> Bool -> Int -> m [(Exp, a)] everythingIO :: (ProgramGeneratorIO pg, Typeable a) => pg -> EveryIO a -- | Those functions are like everything, but take Type as an -- argument, which may be polymorphic. For example, printQ -- ([t| forall a. a->a->a |] >>= return . unifyable -- True 10 memo) will print all the expressions using memo -- whose types unify with forall a. a->a->a. (At first I -- (Susumu) could not find usefulness in finding unifyable expressions, -- but seemingly Hoogle does something alike, and these functions might -- enhance it.) unifyable :: ProgramGenerator pg => pg -> Type -> [[Exp]] -- | Those functions are like everything, but take Type as an -- argument, which may be polymorphic. For example, printQ -- ([t| forall a. a->a->a |] >>= return . unifyable -- True 10 memo) will print all the expressions using memo -- whose types unify with forall a. a->a->a. (At first I -- (Susumu) could not find usefulness in finding unifyable expressions, -- but seemingly Hoogle does something alike, and these functions might -- enhance it.) matching :: ProgramGenerator pg => pg -> Type -> [[Exp]] getEverythingF :: Typeable a => Bool -> IO (Every a) -- | everything generates all the expressions that fit the inferred -- type, and their representations in the Exp form. It returns a -- stream of lists, which is equivalent to Spivey's Matrix data -- type, i.e., that contains expressions consisted of n primitive -- components at the n-th element (n = 1,2,...). everythingF is -- its filtered version everythingF :: (ProgramGenerator pg, Typeable a) => pg -> Bool -> Every a -- | Those functions are like everything, but take Type as an -- argument, which may be polymorphic. For example, printQ -- ([t| forall a. a->a->a |] >>= return . unifyable -- True 10 memo) will print all the expressions using memo -- whose types unify with forall a. a->a->a. (At first I -- (Susumu) could not find usefulness in finding unifyable expressions, -- but seemingly Hoogle does something alike, and these functions might -- enhance it.) unifyableF :: ProgramGenerator pg => pg -> Type -> [[Exp]] -- | Those functions are like everything, but take Type as an -- argument, which may be polymorphic. For example, printQ -- ([t| forall a. a->a->a |] >>= return . unifyable -- True 10 memo) will print all the expressions using memo -- whose types unify with forall a. a->a->a. (At first I -- (Susumu) could not find usefulness in finding unifyable expressions, -- but seemingly Hoogle does something alike, and these functions might -- enhance it.) matchingF :: ProgramGenerator pg => pg -> Type -> [[Exp]] everyF :: (Typeable a, Filtrable a) => Opt b -> Every a -> Every a stripEvery :: Every a -> a -- | pprs pretty prints the results to the console, using -- pprintUC pprs :: Every a -> IO () -- | pprsIO is the EveryIO version of pprs pprsIO :: EveryIO a -> IO () -- | pprsIOn depth eio is the counterpart of pprs (take depth -- eio), while pprsIO eio is the counterpart of pprs -- eio. Example: pprsIOn 5 (everythingIO (mlist::ProgGen) :: -- EveryIO ([Char]->[Char])) pprsIOn :: Int -> EveryIO a -> IO () lengths :: Every a -> IO () lengthsIO :: EveryIO a -> IO () lengthsIOn :: Int -> EveryIO a -> IO () lengthsIOnLn :: Int -> EveryIO a -> IO () printQ :: (Ppr a, Data a) => Q a -> IO () type Primitive = (HValue, Exp, Type) newtype HValue HV :: (forall a. a) -> HValue -- | The function unsafeCoerce# allows you to side-step the -- typechecker entirely. That is, it allows you to coerce any type into -- any other type. If you use this function, you had better get it right, -- otherwise segmentation faults await. It is generally used when you -- want to write a program that you know is well-typed, but where -- Haskell's type system is not expressive enough to prove that it is -- well typed. -- -- The following uses of unsafeCoerce# are supposed to work -- (i.e. not lead to spurious compile-time or run-time crashes): -- --
-- >>> putStrLn $ pprint $ get1 $(c [d| f [] = 0; f [a] = 1; f [a,b] = 2 |]) noBK -- > \a -> let fa (b@([])) = 0 -- > fa (b@(_ : d)) = succ (fa d) -- > in fa a --get1 :: SplicedPrims -> SplicedPrims -> Exp -- | getMany does what you expect from its name. getMany :: SplicedPrims -> SplicedPrims -> [[Exp]] getManyM :: (Search m) => SplicedPrims -> SplicedPrims -> m Exp -- | getManyTyped is a variant of getMany that generates typed -- expressions. This alone is not very useful, but the type info is -- required when compiling the expression and is used in -- MagicHaskeller.RunAnalytical. getManyTyped :: SplicedPrims -> SplicedPrims -> [[Exp]] noBK :: SplicedPrims -- | Also, $(c [d| ... |]) :: SplicedPrims c is a helper -- function for extracting some info from the quoted declarations. c :: Q [Dec] -> ExpQ type SplicedPrims = ([Dec], [Primitive]) -- | Example: -- --
-- >>> runQ [d| f [] = 0; f [a] = 1; f [a,b] = 2 |] >>= \iops -> putStrLn $ pprint $ getOne iops [] -- > \a -> let fa (b@([])) = 0 -- > fa (b@(_ : d)) = succ (fa d) -- > in fa a --getOne :: [Dec] -> [Dec] -> Exp synth :: [Dec] -> [Dec] -> [[Exp]] synthM :: Search m => [Dec] -> [Dec] -> m Exp -- | synthTyped is like synth, but adds the infered type signature -- to each expression. This is useful for executing the expression at -- runtime using GHC API. synthTyped :: [Dec] -> [Dec] -> [[Exp]] module MagicHaskeller.LibExcel succOnlyForNumbers :: Bool last' :: a -> [a] -> a tail :: [a] -> [a] -- | ppExcel replaces uncommon functions like catamorphisms with -- well-known functions. ppExcel :: Exp -> Exp ppv :: Exp -> Exp ppopn :: Name -> Name ppdrop :: Integer -> Exp -> Exp constE :: Exp flipE :: Exp plusE :: Exp dropE :: Exp reverseE :: Exp lengthE :: Exp sumE :: Exp productE :: Exp leftE :: Exp rightE :: Exp lenE :: Exp absE :: Exp mkIF :: Exp -> Exp -> Exp -> Exp mkUncurried :: String -> [Exp] -> Exp mkSUBST4 :: [Exp] -> Exp mkVarOp :: Exp -> String -> Exp -> Exp char7 :: Exp lit0 :: Exp lit1 :: Exp procSucc :: Integer -> Exp -> Exp nrnds :: Num a => [a] mkPgExcel :: IO ProgGenSF mkPgExcels :: Int -> IO ProgGenSF (<>) :: Eq a => a -> a -> Bool excel :: [[(HValue, Exp, Type)]] gcd :: Integral a => a -> a -> a curry2 :: ((a, b) -> c) -> a -> b -> c curry3 :: ((a, b, c) -> d) -> a -> b -> c -> d curry4 :: ((a, b, c, d) -> e) -> a -> b -> c -> d -> e curry5 :: ((a, b, c, d, e) -> f) -> a -> b -> c -> d -> e -> f curry6 :: ((a, b, c, d, e, f) -> g) -> a -> b -> c -> d -> e -> f -> g iF :: (Bool, a, a) -> a upper :: [Char] -> [Char] lower :: [Char] -> [Char] proper :: [Char] -> [Char] right :: RealFrac a => ([b], a) -> [b] left :: RealFrac a => ([b], a) -> [b] left1 :: [a] -> [a] right1 :: [b] -> [b] dropLeft :: RealFrac a => [Char] -> a -> [Char] mid :: (RealFrac a1, RealFrac a2) => ([a], a2, a1) -> [a] len :: Num a => String -> a concatenate :: ([a], [a]) -> [a] concatenatE :: ([a], [a], [a]) -> [a] concatenaTE :: ([a], [a], [a], [a]) -> [a] concatenATE :: ([a], [a], [a], [a], [a]) -> [a] concateNATE :: ([a], [a], [a], [a], [a], [a]) -> [a] cEILING :: (Double, Double) -> Double fLOOR :: (Double, Double) -> Double mround :: (Double, Double) -> Double fLOOR0 :: RealFrac a => a -> a -> a rOUND :: RealFrac a => (Double, a) -> Double roundup :: RealFrac a => (Double, a) -> Double rounddown :: RealFrac a => (Double, a) -> Double trim :: String -> String fIND :: (RealFrac a, Num b) => (String, String, a) -> Maybe b ifERROR :: (Maybe a, a) -> a aND :: (Bool, Bool) -> Bool oR :: (Bool, Bool) -> Bool sign :: Num a => a -> a power :: RealFloat a => (a, a) -> Maybe a sQRT :: (Floating r, Ord r) => r -> Maybe r lOG :: (Floating r, Ord r) => (r, r) -> Maybe r ln :: (Floating r, Ord r) => r -> Maybe r pI :: Floating a => () -> a aTAN2 :: RealFloat a => (a, a) -> a fact :: (Enum r, Num r, Ord r) => r -> Maybe r combin :: (Enum r, Eq r, Fractional r) => (r, r) -> Maybe r mOD :: (RealFrac a, RealFrac b, Num c) => (a, b) -> Maybe c degrees :: Double -> Double radians :: Double -> Double gCD :: (Integral a, RealFrac a1, RealFrac a2) => (a1, a2) -> a findIx :: (Num a, RealFrac a1) => [Char] -> [Char] -> a1 -> a finD :: Num b => (String, String) -> b char :: Int -> [Char] sUBsTITUTE :: (String, String, String) -> String sUBSTITUTE :: RealFrac a => (String, String, String, a) -> String sUB :: (Num a, Ord a) => [Char] -> [Char] -> [Char] -> a -> [Char] sUBST4 :: RealFrac a => String -> String -> String -> a -> String countStr :: Num a => String -> String -> a gCD'2 :: Int -> Int -> Int mOD'2 :: Int -> Int -> Maybe Int combin'2 :: Int -> Int -> Maybe Int aTAN2'2 :: Double -> Double -> Double lOG'2 :: Double -> Double -> Maybe Double power'2 :: Double -> Double -> Maybe Double oR'2 :: Bool -> Bool -> Bool aND'2 :: Bool -> Bool -> Bool ifERROR'2 :: Maybe c -> c -> c rounddown'2 :: Double -> Int -> Double roundup'2 :: Double -> Int -> Double rOUND'2 :: Double -> Int -> Double mround'2 :: Double -> Double -> Double cEILING'2 :: Double -> Double -> Double concatenate'2 :: [a] -> [a] -> [a] right'2 :: [b] -> Int -> [b] left'2 :: [b] -> Int -> [b] concatenatE'3 :: [a] -> [a] -> [a] -> [a] sUBsTITUTE'3 :: String -> String -> String -> String fIND'3 :: String -> String -> Int -> Maybe Int mid'3 :: [a] -> Int -> Int -> [a] iF'3 :: Bool -> d -> d -> d concatenaTE'4 :: [a] -> [a] -> [a] -> [a] -> [a] concatenATE'5 :: [a] -> [a] -> [a] -> [a] -> [a] -> [a] concateNATE'6 :: [a] -> [a] -> [a] -> [a] -> [a] -> [a] -> [a] module MagicHaskeller.Minimal e :: Typeable a => (Exp -> Exp) -> a -> ProgGenSF -> Bool -> [[Exp]] f1E :: Typeable a => (Exp -> Exp) -> (a -> Bool) -> ProgGenSF -> Bool -> [[Exp]] f1EF :: (Filtrable a, Typeable a) => (Exp -> Exp) -> (a -> Bool) -> ProgGenSF -> Bool -> [[Exp]] f1EIO :: Typeable a => (Exp -> Exp) -> (a -> Bool) -> ProgGenSF -> Bool -> IO [[Exp]] f1EFIO :: (Filtrable a, Typeable a) => (Exp -> Exp) -> (a -> Bool) -> ProgGenSF -> Bool -> IO [[Exp]] type ProgGenSF = PGSF CoreExpr class NearEq a (~=) :: NearEq a => a -> a -> Bool -- | postprocess replaces uncommon functions like catamorphisms with -- well-known functions. postprocess :: Exp -> Exp -- | ppExcel replaces uncommon functions like catamorphisms with -- well-known functions. ppExcel :: Exp -> Exp module MagicHaskeller.RunAnalytical -- | Example of quickStart -- --
-- >>> quickStart [d| f [] = 0; f [a] = 1 |] noBKQ (\f -> f "12345" == 5) -- > \a -> let fa (b@([])) = 0 -- > fa (b@(c : d)) = succ (fa d) -- > in fa a :: forall t2 . [t2] -> Int -- > ^CInterrupted. --quickStart :: (Typeable a) => Q [Dec] -> Q [Dec] -> (a -> Bool) -> IO () quickStartF :: (Filtrable a, Typeable a) => Q [Dec] -> Q [Dec] -> (a -> Bool) -> IO () filterGetOne_ :: Typeable * a => HscEnv -> Q [Dec] -> (a -> Bool) -> IO () filterGetOne :: (Typeable a) => HscEnv -> Q [Dec] -> (a -> Bool) -> IO (Every a) filterGetOneBK :: (Typeable a) => HscEnv -> Q [Dec] -> Q [Dec] -> (a -> Bool) -> IO (Every a) synthFilt :: (Typeable a) => HscEnv -> Q [Dec] -> Q [Dec] -> (a -> Bool) -> IO (Every a) synthFiltF :: (Filtrable a, Typeable a) => HscEnv -> Q [Dec] -> Q [Dec] -> (a -> Bool) -> IO (Every a) synthAll :: (Typeable a) => HscEnv -> Q [Dec] -> Q [Dec] -> IO (Every a) noBKQ :: Q [Dec]