-
Notifications
You must be signed in to change notification settings - Fork 84
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
Fin n
for array indexes?
#313
Comments
What utility would that offer? It certainly would incur a high complexity toll on the code base. |
Well have you seen this happy/lib/grammar/src/Happy/Grammar.lhs Lines 120 to 142 in 4b59fb3
in particular
Makes me chuckle. My trying to turn |
Also, it gives us a way to pull some metadata out of band. I am thinking of something like data Grammar eliminator
= Grammar {
productions :: [Production eliminator],
lookupProdNo :: Int -> Production eliminator,
lookupProdsOfName :: Name -> [Int],
token_specs :: [(Name, TokenSpec)],
terminals :: [Name],
non_terminals :: [Name],
starts :: [(String,Name,Name,Bool)],
types :: Array Int (Maybe String),
token_names :: Array Int String,
first_nonterm :: Name,
first_term :: Name,
eof_term :: Name,
priorities :: [(Name,Priority)]
} to type Name nStarts nTerms nNonTerms = Fin (4 + nStarts + nTerms + nNonTerms)
data Production = Production
(Fin nNonTerms)
[Name nStarts nTerms nNonTerms]
-- IIRC these are indices of the previous list,
-- so could do more dep types
[Word]
Priority
data Grammar nStarts nTerms nNonTerms
= Grammar {
-- No longer need eliminator type parameter
productions :: Vector nProds (Production nStarts nTerms nNonTerms),
lookupProdsOfName :: Map (Fin nNonTerms) (Set (Fin nProds)),
starts :: Vector nStarts (Name, Bool),
priorities :: Map (Fin nNonTerms) Priority
} which is the core formal language part (?) and data GrammarExtras nStarts nTerms nNonTerms
= GrammarExtras {
prod_elims :: Vector nNonTerms Text,
token_elims :: Vector nTerms TokenSpec,
start_names :: Vector nStarts Text,
start_names :: Vector nStarts Text,
types :: Vector nTerms (Maybe Text),
token_names :: Vector nTerms Text,
} has all the extras bits for human legibility and/or codegen, with guarantees from the type parameters that everything has the right arities. |
From what I remember, I don't like the overhead of dependent stuff in Haskell either, but I am not sure how else lock down the data structures without changing around the terms more. For example, one can do zip all lists/arrays of the same arity to ditch the coherence conditions, and use "expansion points" as needed to factor out the extra info", and that works pretty well, but the various index types we need to store (because it's a graph, at the end of the day) are not helped by this. |
But you ultimately need I still don't see the utility of using |
Fair enough, I was thinking of #223 as a stepping stone already, and you are rightly pointing out there are more newtypes we can create as further stepping stones. |
Happy currently has a lot of "untyped" array indexing, where nothing stops one using an index for the wrong of e.g. tokens, non-terminals, terminals.
I haven't done finite sets in Haskell for a while, so not sure the state of things these days (still
KnownNat
and friends I suppose?), but I wonder if we should try using them. It would be a lot less scary to refactor the code if these indexes wouldn't be confused for one another.The text was updated successfully, but these errors were encountered: