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

Safe HaskellNone
LanguageHaskell2010

ADP.Fusion.Base.Classes

Synopsis

Documentation

data OutsideContext s Source

Constructors

OStatic s 
ORightOf s 
OFirstLeft s 
OLeftOf s 

Instances

data InsideContext s Source

Constructors

IStatic s 
IVariable s 

Instances

class RuleContext i where Source

Associated Types

type Context i :: * Source

Methods

initialContext :: i -> Context i Source

data family RunningIndex i :: * Source

While we ostensibly use an index of type i we typically do not need every element of an i. For example, when looking at Subwords, we do not need both element of j:.k but only k. Also, inside grammars do need fewer moving indices than outside grammars.

TODO Sometimes, the actual RunningIndex ctors are not erased. This could be due to https://ghc.haskell.org/trac/ghc/ticket/2289. To test, we should transform RunningIndex into a type class to give us access to the left and right member, also we should create instances a la RunningIndex (is :. Subword I) = RiSwI !(RunningIndex is) !Int. Hopefully, these are completely erased.

Instances

Show (RunningIndex Z) Source 
GetIndexGo (RunningIndex Z) (RunningIndex Z) EQ Source 
GetIndexGo (RunningIndex ix) (RunningIndex Z) (CmpNat (ToNat (RunningIndex ix)) (ToNat (RunningIndex Z))) => GetIndexGo (RunningIndex ((:.) ix i)) (RunningIndex Z) GT Source 
GetIndexGo (RunningIndex ix) (RunningIndex ((:.) my m)) (CmpNat (ToNat (RunningIndex ix)) (ToNat (RunningIndex ((:.) my m)))) => GetIndexGo (RunningIndex ((:.) ix i)) (RunningIndex ((:.) my m)) GT Source 
GetIndexGo (RunningIndex ((:.) ix i)) (RunningIndex ((:.) my m)) EQ Source 
data RunningIndex Z = RiZ Source 
data RunningIndex (Subword I) = RiSwI Int Source

The moving index k in Subword (i:.k).

data RunningIndex (Subword O) = RiSwO !Int !Int !Int !Int Source

The moving indices Inside (i:.j) and Outside (k:.l) in order i j k l.

TODO can we do with 2x Int?

data RunningIndex (Subword C) = RiSwC !Int !Int Source

The indices Subword (i:.j) in order i j.

data RunningIndex (BitSet I) = RiBsI (BitSet I) Source 
data RunningIndex (BitSet O) = RiBsO !(BitSet O) !(BitSet O) Source 
data RunningIndex (BitSet C) = RiBsC !(BitSet C) !(BitSet C) Source 
data RunningIndex (PointL I) = RiPlI Int Source 
data RunningIndex (PointL O) = RiPlO !Int !Int Source 
data RunningIndex (PointL C) = RiPlC !Int Source 
data RunningIndex (Unit t) = RiU Source 
type ToNat (RunningIndex Z) = 0 Source 
type ToNat (RunningIndex ((:.) is i)) = (+) (ToNat (RunningIndex is)) 1 Source 
type ResolvedIx (RunningIndex Z) (RunningIndex Z) EQ = RunningIndex Z Source 
type ResolvedIx (RunningIndex ((:.) ix i)) (RunningIndex Z) GT = ResolvedIx (RunningIndex ix) (RunningIndex Z) (CmpNat (ToNat (RunningIndex ix)) (ToNat (RunningIndex Z))) Source 
type ResolvedIx (RunningIndex ((:.) ix i)) (RunningIndex ((:.) my m)) GT = ResolvedIx (RunningIndex ix) (RunningIndex ((:.) my m)) (CmpNat (ToNat (RunningIndex ix)) (ToNat (RunningIndex ((:.) my m)))) Source 
type ResolvedIx (RunningIndex ((:.) ix i)) (RunningIndex ((:.) my m)) EQ = RunningIndex i Source 
data RunningIndex ((:.) is i) = !(RunningIndex is) :.: !(RunningIndex i) Source 
data RunningIndex (BS2 First Last I) = RiBs2I (BS2 First Last I) Source 
data RunningIndex (BS2 First Last O) = RiBs2O !(BS2 First Last O) !(BS2 First Last O) Source 
data RunningIndex (BS2 First Last C) = RiBs2C !(BS2 First Last C) !(BS2 First Last C) Source 

class Element x i where Source

During construction of the stream, we need to extract individual elements from symbols in production rules. An element in a stream is fixed by both, the type x of the actual argument we want to grab (say individual characters we parse from an input) and the type of indices i we use.

Elm data constructors are all eradicated during fusion and should never show up in CORE.

Associated Types

data Elm x i :: * Source

type RecElm x i :: * Source

type Arg x :: * Source

Methods

getArg :: Elm x i -> Arg x Source

getIdx :: Elm x i -> RunningIndex i Source

getElm :: Elm x i -> RecElm x i Source

Instances

Element S i Source 
((~) * s (Elm x0 i), Element x0 i) => Element (Term1 s) ((:.) Z i) Source 
((~) * s (Elm x0 i), Element x0 i) => Element (SynVar1 s) ((:.) Z i) Source 
Element ls i => Element ((:!:) ls (TermSymbol a b)) i Source 
Element ls i => Element ((:!:) ls (Backtrack (ITbl mF arr c j x) mF mB r)) i Source 
Element ls i => Element ((:!:) ls (ITbl m arr c j x)) i Source 
Element ls i => Element ((:!:) ls (Backtrack (IRec mF c u x) mF mB r)) i Source 
Element ls i => Element ((:!:) ls (IRec m c u x)) i Source 
Element ls i => Element ((:!:) ls (Split uId splitType (Backtrack (ITbl mF arr c j x) mF mB r))) i Source 
Element ls i => Element ((:!:) ls (Split uId splitType (ITbl m arr c j x))) i Source 
Element ls i => Element ((:!:) ls (Chr r x)) i Source 
Element ls i => Element ((:!:) ls Deletion) i Source 
Element ls i => Element ((:!:) ls (Edge e)) i Source 
Element ls i => Element ((:!:) ls Epsilon) i Source 
Element ls i => Element ((:!:) ls (PeekIndex i)) i Source 
Element ls i => Element ((:!:) ls (Strng v x)) i Source 

class Monad m => MkStream m x i where Source

mkStream creates the actual stream of elements (Elm) that will be fed to functions on the left of the (<<<) operator. Streams work over all monads and are specialized for each combination of arguments x and indices i.

Methods

mkStream :: x -> Context i -> i -> i -> Stream m (Elm x i) Source

Instances

(Monad m, MkStream m ls i, Element ls i, TermStaticVar (TermSymbol a b) i, TermStream m (TermSymbol a b) (Elm ls i) i) => MkStream m ((:!:) ls (TermSymbol a b)) i Source 
(Monad mB, Element ls ((:.) is i), TableStaticVar ((:.) us u) ((:.) cs c) ((:.) is i), AddIndexDense (Elm ls ((:.) is i)) ((:.) us u) ((:.) cs c) ((:.) is i), MkStream mB ls ((:.) is i), PrimArrayOps arr ((:.) us u) x) => MkStream mB ((:!:) ls (Backtrack (ITbl mF arr ((:.) cs c) ((:.) us u) x) mF mB r)) ((:.) is i) Source 
(Monad m, Element ls ((:.) is i), TableStaticVar ((:.) us u) ((:.) cs c) ((:.) is i), AddIndexDense (Elm ls ((:.) is i)) ((:.) us u) ((:.) cs c) ((:.) is i), MkStream m ls ((:.) is i), PrimArrayOps arr ((:.) us u) x) => MkStream m ((:!:) ls (ITbl m arr ((:.) cs c) ((:.) us u) x)) ((:.) is i) Source 
(Monad mB, Element ls ((:.) is i), TableStaticVar ((:.) us u) ((:.) cs c) ((:.) is i), AddIndexDense (Elm ls ((:.) is i)) ((:.) us u) ((:.) cs c) ((:.) is i), MkStream mB ls ((:.) is i)) => MkStream mB ((:!:) ls (Backtrack (IRec mF ((:.) cs c) ((:.) us u) x) mF mB r)) ((:.) is i) Source 
(Monad m, Element ls ((:.) is i), TableStaticVar ((:.) us u) ((:.) cs c) ((:.) is i), AddIndexDense (Elm ls ((:.) is i)) ((:.) us u) ((:.) cs c) ((:.) is i), MkStream m ls ((:.) is i)) => MkStream m ((:!:) ls (IRec m ((:.) cs c) ((:.) us u) x)) ((:.) is i) Source 

class Build x where Source

Finally, we need to be able to correctly build together symbols on the right-hand side of the (<<<) operator.

The default makes sure that the last (or only) argument left over is correctly assigned a Z to terminate the symbol stack.

Minimal complete definition

Nothing

Associated Types

type Stack x :: * Source

Methods

build :: x -> Stack x Source

Instances

Build Deletion Source 
Build Epsilon Source 
Build (Edge e) Source 
Build (PeekIndex i) Source 
Build x => Build ((:!:) x y) Source 
Build (TermSymbol a b) Source 
Build (Chr r x) Source 
Build (Strng v x) Source 
Build (Split uId splitType synVar) Source 
Build (Backtrack t mF mB r) Source 
Build (IRec m c i x) Source 
Build (ITbl m arr c i x) Source 

data S Source

Similar to Z, but terminates an argument stack.

Constructors

S 

Instances

Eq S Source 
Show S Source 
Element S i Source 
SplitIxCol uId b (Elm S i) Source 
Show (RunningIndex ix) => Show (Elm S ix) Source 
data Elm S = ElmS !(RunningIndex i) Source 
type Arg S = Z Source 
type SplitIxTy uId b (Elm S i) = Z Source 

staticCheck :: Monad m => Bool -> Stream m a -> Stream m a Source

staticCheck acts as a static filter. If b is true, we keep all stream elements. If b is false, we discard all stream elements.

data StaticCheck a b Source

Constructors

CheckLeft Bool a 
CheckRight b 

data EmptyOk Source

Constrains the behaviour of the memoizing tables. They may be EmptyOk if i==j is allowed (empty subwords or similar); or they may need NonEmpty indices, or finally they can be OnlyZero (only i==j allowed) which is useful in multi-dimensional casese.

Constructors

EmptyOk 

Instances

MinSize EmptyOk Source 
type TNE (Backtrack (ITbl mF arr EmptyOk i x) mF mB r) = Backtrack (ITbl mF arr NonEmpty i x) mF mB r Source 
type TE (Backtrack (ITbl mF arr EmptyOk i x) mF mB r) = Backtrack (ITbl mF arr EmptyOk i x) mF mB r Source 
type TNE (ITbl m arr EmptyOk i x) = ITbl m arr NonEmpty i x Source 
type TE (ITbl m arr EmptyOk i x) = ITbl m arr EmptyOk i x Source 

data NonEmpty Source

Constructors

NonEmpty 

class MinSize c where Source

Methods

minSize :: c -> Int Source

class ModifyConstraint t where Source

TODO Rewrite to generalize easily over multi-dim cases.

Associated Types

type TNE t :: * Source

type TE t :: * Source

Methods

toNonEmpty :: t -> TNE t Source

toEmpty :: t -> TE t Source