[Haskell-cafe] Parsec and (then?) type-check
sam lee
skynare at gmail.com
Fri Dec 12 20:27:28 EST 2008
I use my type checking monad, which is separate from Parsec's monad.
So, I can't think of a way to type check during parsing in Parsec's monad.
Anyways, this is what I did:
data Expr = ... | At SourcePos Expr
SourcePos is from Parsec.
Basically, my parse actions will return (At pos e).
And I pass At pos e to typeCheck action.
typeCheck (At pos e) = do
put pos
-- typeCheck is in State monad.
-- in case of error, I'll pos <- get and report source position.
typeCheck e
typeCheck (Variable a) = do
...
check out this:
http://www.lipl.googlepages.com/index.html#source
On Fri, Dec 12, 2008 at 5:06 PM, Greg Fitzgerald <garious at gmail.com> wrote:
> Parser gurus,
>
> When you write a parser with a library like Parsec, do you typically
> type-check while parsing, or afterward in a separate pass? The latter
> is more modular, but it means labeling every element in the AST with
> the parser position so that you can give good error messages. Do you
> find the added modularity worth the hassle or just pack type-checking
> into the parser pass?
>
> Thanks,
> Greg
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
More information about the Haskell-Cafe
mailing list