AndrasKovacs / AndrasKovacs/flatparse

Adding PrimMonad instance for parsers

Open
#61 2 comments 0 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.