ADPfusion-0.4.0.2: Efficient, high-level dynamic programming.

Safe HaskellNone
LanguageHaskell2010

ADP.Fusion.TH.Backtrack

Description

Backtracking which uses lists internally. The basic idea is to convert each Stream into a list. The consumer consumes the stream lazily, but allows for fusion to happen. The hope is that this improves total performance in those cases, where backtracking has significant costs.

Synopsis

Documentation

class BacktrackingProduct sigF sigB where Source

The type class of algebra products. We have the forward signature sigF and the backtracking signature sigB. Combined via (<||) we have a new signature SigR.

Associated Types

type SigR sigF sigB :: * Source

Methods

(<||) :: sigF -> sigB -> SigR sigF sigB Source

getMonadName :: [TyVarBndr] -> Maybe Name Source

Returns the Name of the monad variable.

getObjectiveNames :: [VarStrictType] -> Maybe (Name, Name, Name, Name) Source

Returns the Names of the objective function variables, as well as the name of the objective function itself.

genAttributeFunction :: [Name] -> Name -> Name -> VarStrictType -> Q (Name, Exp) Source

TODO need fun names from l and r

recBuildLamPat :: [Name] -> Name -> Name -> [Name] -> Q ([Pat], Exp, Exp) Source

buildRns :: Exp -> [Pat] -> ExpQ Source

NOTE

[ f x | x <- xs ]
CompE [BindS (VarP x) (VarE xs), NoBindS (AppE (VarE f) (VarE x))]

buildBacktrackingChoice :: Name -> Name -> Q Exp Source

Build up the backtracking choice function. This choice function will backtrack based on the first result, then return only the second.

TODO it should be (only?) this function we will need to modify to build all algebra products.

ysM can't be unboxed, as snd of each element is a list, lazily consumed. We build up ysM as this makes fusion happen. Of course, this is a boxed vector and not as efficient, but we gain the ability to have lazily created backtracking from this!

This means strict optimization AND lazy backtracking

streamToVector :: Monad m => Stream m x -> m (Vector x) Source

Transform a monadic stream monadically into a vector.

vectorToStream :: Monad m => Vector x -> Stream m x Source

Transform a vector into a monadic stream.

getRuleSynVarNames :: Type -> [Name] Source

Gets the names used in the evaluation function. This returns one Name for each variable.

In case of TupleT 0 the type is () and there isn't a name to go with it. We just mkName "()" a name, but this might be slightly dangerous? (Not really sure if it indeed is)

With AppT _ _ we have a multidim terminal and produce another hackish name to be consumed above.

AppT (AppT ArrowT (AppT (AppT (ConT Data.Array.Repa.Index.:.) (AppT (AppT (ConT Data.Array.Repa.Index.:.) (ConT Data.Array.Repa.Index.Z)) (VarT c_1627675270))) (VarT c_1627675270))) (VarT x_1627675265)