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

Explore unboxed parser representations #193

Open
Boarders opened this issue Sep 15, 2021 · 0 comments
Open

Explore unboxed parser representations #193

Boarders opened this issue Sep 15, 2021 · 0 comments

Comments

@Boarders
Copy link

There is a nice library by Ed Kmett called parsnip: https://hackage.haskell.org/package/parsnip-0/

This represents a parser as follows:

newtype Option a = Option# (# a | (##) #)
type Result s a = (# Option a, Addr#, State# s #)

newtype Parser s a = Parser
 { runParser :: Addr# -> State# s -> Result s a
 }

Here is how the Alex parser for monad-bytestring looks:

newtype Alex a = Alex { unAlex :: AlexState -> Either String (AlexState, a) }

-- monad-bytestring wrapper
data AlexState = AlexState {
       alex_pos :: !AlexPosn,  -- position at current input location
       alex_bpos:: !Int64,     -- bytes consumed so far
       alex_inp :: ByteString.ByteString,      -- the current input
       alex_chr :: !Char,      -- the character before the input
       alex_scd :: !Int        -- the current startcode
     , alex_ust :: AlexUserState -- AlexUserState will be defined in the user program
   }

It seems this sort of unboxing experiment is not so far out of reach for a wrapper that could produce potentially very fast code. On top of that, as it is user-generated code it seems reasonable that it might be quite horrid to actually read. How feasible would it be to add a wrapper inspired by parsnip?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant