Symbol-parser: Type level string parser combinators

“I love types. I store all my strings there. But I must reify to parse them!” I hear you (me) lament.
Fret not. Simply parse them on the type level with symbol-parser:

ghci> import Data.Type.Symbol.Parser
ghci> :k! RunParser (Drop 3 :*>: Isolate 2 NatDec :<*>: (Drop 3 :*>: NatHex)) "___10___FF"
...
= Right '( '(10, 255), "")

And so on. There are a small handful of combinators, and you can write your own if you wish.

This felt very silly to write, but I eventually realized it’s fairly useful for generics which want to be safer & faster at runtime, and I don’t think it’s been written yet (it relies on UnconsSymbol, which was released with GHC 9.2). The code is fairly messy, and I would appreciate any suggestions or contributions!

/r/haskell post: https://www.reddit.com/r/haskell/comments/1c6fpbj

7 Likes