AndrasKovacs / AndrasKovacs/flatparse
Adding PrimMonad instance for parsers
Nobody has claimed this yet.
- Dominant language
- Haskell
- Stars
- 178
- Forks
- 18
- PR merge metrics
- No merged PRs in 30d
Description
What do you think about adding PrimMonad instances for parses? It does add dependency on primitive but I don't think it's too bad. It provides standard API for working with mutable state and all required pieces are already in place.
instance PrimMonad (ParserT (State# s) e) where
type PrimState (ParserT (State# s) e) = s
primitive = liftST . primitive
{-# INLINE primitive #-}
Main reason to add them is to allow passing parsers as callbacks into functions working with mutable state:
replicateVec :: Int -> Parser e a -> Parser e (Vector a)
replicateVec n elt = embedParserST $ do
mvec <- MV.replicateM n (embedParser elt)
V.unsafeFreeze mvec
without PrimMonad instance it's not possible to pass parser as parameter to replicateM and one will have to write loop by hand
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the ParserT definition and the existing liftST, embedParserST, and primitive entry points referenced in the issue. Check the primitive dependency and the parser transformer instances, then verify the proposed PrimMonad behavior with the mutable-vector callback example; done means the instance is integrated without breaking existing parser APIs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100