Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data Value should be a Monoid #9

Open
MarkusLeupold opened this issue Feb 10, 2021 · 0 comments
Open

data Value should be a Monoid #9

MarkusLeupold opened this issue Feb 10, 2021 · 0 comments
Labels
bibtoxml Related to the bibtoxml program enhancement New feature or request

Comments

@MarkusLeupold
Copy link
Owner

MarkusLeupold commented Feb 10, 2021

Scope: bibtoxml/src/BibTeX/Types.hs

In BibTeX, values can be concatenated to form a new value. BibTeX.Types supports this feature, but the implementation can be more precise: If you look closely, you will see that the set of all possible values forms a monoid together with the contatenation operation defined on it. Here's the proof:

Value is the set of all possible values. Each element v of Value has the data type Value and is constructed using one of the three constructors LiteralValue, ReferencedValue, and ComposedValue.

Also, we define the expansion operation e of a value:

e :: Value -> String

where e v is the expanded string representation of v (i.e. the meaning of v as ordinary text, with variable references replaced by their definition recursively)

Third, we define the concatenation operation <+> like following:

<+>: V x V --> V

where r = v1 <+> v2 is defined such that e r == e v1 ++ e v2.

The Value type in BibTeX.Types is not the actual value of a field. Semantically, a field's value is equal to the expansion of its Value element. The internal representation of a field's value therefore has to simulate the semantics of its expansion. This means, that concatenating Value elements is semantically equivalent to concatenating their expansions.
Because of that, Values inherit all characteristics from Strings which are based on the String concatenation (++). Strings form a Monoid with their concatenation, and therefore also Values do, q.e.d.

It would be a good idea to adapt the Value type according to Monoid laws and create a corresponding instance of Monoid. This will make the properties of Value easier to see and understand and therefore improve code quality.

@MarkusLeupold MarkusLeupold added enhancement New feature or request bibtoxml Related to the bibtoxml program labels Feb 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bibtoxml Related to the bibtoxml program enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant