Closed clayrat closed 4 years ago
More of a design discussion: I am not sure that insisting that the list of keywords is non empty actually brings anything to the table. I am tempted to drop this requirement when I finally update agdarsec to use tries.
Yeah I was thinking about changing keywords
to be a SortedMap
instead.
I've tried changing keywords
to SortedMap
but that creates problems for the typelevel test, because most of the declarations in that module are either private
or export
, so we can't evaluate the type completely. Also it doesn't buy us much since we only use it in init
by immediately converting to List
. OTOH a more specific type would guarantee key uniqueness, WDYT?
Also I've removed implicit declarations for LexParameters
, but we'll have to bring most of them back for Idris2 to override the default erasure quantity.
Btw, is there a reason to use b ** if b then Maybe Tok else ()
instead of something like Maybe (Maybe Tok)
?
I think Maybe (Maybe Token)
blurs the intent. Tbh it may be worth introducing
a domain-specific sum type:
data MaybeBreaking : Set where
IsBreaking : Maybe Tok -> MaybeBreaking
IsNotBreaking : MaybeBreaking
OTOH a more specific type would guarantee key uniqueness, WDYT?
Oh I see. I had not thought of that. An alternative is to use a fresh list, a cute data structure defined by induction recursion for elements types with a decidable equality.
Edit: SortedMap
did guarantee that the input was repetition free but had the user
called fromList
to construct it, they would lose all guarantees... So a list
is at least as good as a SortedMap
I think, and we can use a fresh list if we
really want to enforce uniqueness of keywords.
An alternative is to use a fresh list, a cute data structure defined by induction recursion for elements types with a decidable equality.
Could you point me to some examples of fresh lists? Anyway I think this can probably be handled in a separate PR.
I have opened a PR to the Agda standard library with an implementation of fresh lists together with documentation & an updated version of the lexer example using fresh lists.
Closes https://github.com/gallais/idris-tparsec/issues/22