Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Scoring.Deprecated.Flat
Description
This module is deprecated, use Scoring.FunTyped instead.
Semiring scores with "holes". Holes are used to express "partially applied" scores that occur when the score of a verticalization (unspread) is distributed to two parent edges. The full score of the operation is restored when the two parent edges are eventually combined again.
This module implements partial scores using lists, which is slow and not very elegant. The grammar combinators are partial and will fail if used incorrectly, indicating parser bugs.
Synopsis
- data Score s i
- type Holes s = [s]
- val :: s -> Score s i
- newtype LeftId i = LeftId i
- newtype RightId i = RightId i
- leftSide :: Score s i -> Maybe (LeftId i)
- rightSide :: Score s i -> Maybe (RightId i)
- showScore :: (Show s, Show i) => Score s i -> String
- times :: (Semiring s, Eq i, Show i) => Score s i -> Score s i -> Maybe (Score s i)
- plus :: (Semiring s, Eq i) => Score s i -> Score s i -> Maybe (Score s i)
- unsplitScores :: (Semiring s, Eq i, Show i, Show s) => s -> Score s i -> Score s i -> Score s i
- unspreadScoresLeft :: (Eq i, Show i, Semiring s, Show s) => i -> Score s i -> Score s i
- unspreadScoresRight :: (Eq i, Semiring s, Show i, Show s) => i -> s -> Score s i -> Score s i -> Score s i
- addScores :: (Semiring s, Eq i) => Score s i -> Score s i -> Score s i
- getScoreVal :: Score s i -> s
The Score Type
A partially applied score of type s
.
Comes in four variants,
depending on whether the score is fully applied
or needs to be combined on either or both sides.
Values that need to be combined are lists that represent scores with holes.
Each variant carries IDs of type i
that determine which objects fit on either of its sides.
Only score objects with matching IDs can be combined.
As a shorthand notation, we use a-b
to indicate a value
that depends on a
on its left and on b
on its right.
If the value does not depend on anything on either side, we use ()
,
i.e. ()-a
stands for SLeft _ a
and ()-()
stands for SVal _
.
Constructors
SVal !s | Carries a fully applied value |
SRight !(LeftId i) ![Holes s] | The right part of a combination, expects an argument to its left. Implemented as a list of right elements |
SLeft ![Holes s] !(RightId i) | The left part of a combination, expects an argument to its right. Implemented as a list of right elements |
SBoth !(LeftId i) ![(Holes s, Holes s)] !(RightId i) | A combination of |
Instances
Newtype for the left ID of a partial score.
Constructors
LeftId i |
Instances
Generic (LeftId i) Source # | |
Show i => Show (LeftId i) Source # | |
NFData i => NFData (LeftId i) Source # | |
Defined in Scoring.Deprecated.Flat | |
Eq i => Eq (LeftId i) Source # | |
Ord i => Ord (LeftId i) Source # | |
Defined in Scoring.Deprecated.Flat | |
Hashable i => Hashable (LeftId i) Source # | |
Defined in Scoring.Deprecated.Flat | |
type Rep (LeftId i) Source # | |
Defined in Scoring.Deprecated.Flat |
Newtype for the right ID of a partial score.
Constructors
RightId i |
Instances
Generic (RightId i) Source # | |
Show i => Show (RightId i) Source # | |
NFData i => NFData (RightId i) Source # | |
Defined in Scoring.Deprecated.Flat | |
Eq i => Eq (RightId i) Source # | |
Ord i => Ord (RightId i) Source # | |
Hashable i => Hashable (RightId i) Source # | |
Defined in Scoring.Deprecated.Flat | |
type Rep (RightId i) Source # | |
Defined in Scoring.Deprecated.Flat |
Semiring operations
Semiring operations can be lifted to partial scores, but since it is not guaranteed that their arguments can be combined, they are partial.
grammatical combinators
The following combinators correspond to the unsplit and unspread operations of the path-graph grammar.
Arguments
:: (Semiring s, Eq i, Show i, Show s) | |
=> s | The score of the split operation. |
-> Score s i | The |
-> Score s i | The |
-> Score s i | The |
Combines the Score
s of two edges with a split
operation into the score of the parent edge.
This is expected to be called on compatible scores
and will throw an error otherwise to indicate parser bugs.
a-b b-c --------- unsplit a-c
Arguments
:: (Eq i, Show i, Semiring s, Show s) | |
=> i | The new ID that marks both parent edges |
-> Score s i | The |
-> Score s i | The |
Creates the Score
of a left parent edge from a left child edge of an unspread
.
Will throw an error if called on invalid input to indicate parser bugs.
Arguments
:: (Eq i, Semiring s, Show i, Show s) | |
=> i | The new ID that marks both parent edges. |
-> s | The score of the |
-> Score s i | The |
-> Score s i | The |
-> Score s i | The |
Creates the Score
of a right parent edge
from the middle and right child edges of an unspread
and a spread
operation.
addScores :: (Semiring s, Eq i) => Score s i -> Score s i -> Score s i Source #
Adds two Score
s that are alternative derivations of the same transition.
This is expected to be called on compatible scores
and will throw an error otherwise to indicate parser bugs.
a-b a-b --------- add a-b
getScoreVal :: Score s i -> s Source #
Extracts the value from a fully applied Score
.
This function is intended to be used to extract the final score of the parser.
If the score is not fully applied,
throws an exception to indicate parser bugs.