[Haskell-cafe] Parsec without data declarations/AST

Alexander Solla alex.solla at gmail.com
Wed Feb 20 00:22:05 CET 2013


Come to think of it, a parsec parser already wraps over Either, so if all
you want to do is check if a result is valid, you can abuse the Either
semantics so that your type is:

Parser () -- the parser which returns nothing on success or an error on
failure.


On Tue, Feb 19, 2013 at 3:20 PM, Alexander Solla <alex.solla at gmail.com>wrote:

> If all you want to do is check that the code is valid (i.e., you aren't
> going to interpret the code), you can just return a Bool.  If you want to
> interpret it, but don't want to have a Stmt type, you can return IO ()
> actions.  In that case, the parser's type will be
>
> Parser (IO ())
>
> I think an algebraic AST (or even a functorial/monadic one) will help
> separate concerns, and will eventually help when it comes time to optimize
> your compiler.  It really isn't as much boilerplate as it looks like (in
> fact, there's hardly any boilerplate if you target free monads and
> interpret those in IO), and you get the type safety for which Haskell is
> well-known.
>
>
>
> On Tue, Feb 19, 2013 at 3:02 PM, Sean Cormican <seancormican1 at gmail.com>wrote:
>
>> I have been trying to create a parser for a functional programming
>> language, but there is no need to create an AST but merely check that the
>> code is valid according to the grammar.
>>
>> In the following tutorial I have been trying to take some pointers from,
>> data declarations are used to create an AST for the language, There is, as
>> I understand a way to parse the language without an AST.
>>
>> http://www.haskell.org/haskellwiki/Parsing_a_simple_imperative_language
>>
>> My question is what should the type signatures for example parseFile
>> function instead of "Stmt" accept as input if the parser is to accept
>> Strings and numerical expressions alike ?
>>
>> Thanks for any help,
>> Seán
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130219/573d1988/attachment.htm>


More information about the Haskell-Cafe mailing list