[Haskell-cafe] Parsec: buildExpressionParser of a different type than parsed term

2007-04-09 Thread Joel Reymont

Folks,

I'm trying to parse NumExpr  NumExpr (example) which should return a  
logical expression while parsing numeric terms. I can't figure out  
how to make buildExpressionParser do this for me since it takes the  
type of the term parser given to it. If I supply a parser for numeric  
terms then I cannot return a logical expression.


How can this be resolved?

Note that I do not want to put all expressions into the same Expr  
type since it makes generating valid random ASTs with QuickCheck  
impossible.


Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Parsec: buildExpressionParser of a different type than parsed term

2007-04-09 Thread Albert Y. C. Lai

Joel Reymont wrote:
I'm trying to parse NumExpr  NumExpr (example) which should return a 
logical expression while parsing numeric terms. I can't figure out how 
to make buildExpressionParser do this for me since it takes the type of 
the term parser given to it. If I supply a parser for numeric terms then 
I cannot return a logical expression.

[...]
Note that I do not want to put all expressions into the same Expr type 
since it makes generating valid random ASTs with QuickCheck impossible.


As you probably suspect, one single use of buildExpressionParser cannot 
accomplish it. It is equivalent to the problem of homogeneous lists.


However, you can make two uses of buildExpressionParser, one for numeric 
expressions and the other for logical expressions. Mutual reference is 
no problem since, in all practical uses, even with just one single 
buildExpressionParser you already have the term parser call its own 
buildExpressionParser; now you just have one term parser call the 
other's buildExpressionParser. Sharing the same token parser is 
perfectly alright.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Parsec: buildExpressionParser of a different type than parsed term

2007-04-09 Thread Joel Reymont

Albert,

On Apr 10, 2007, at 12:19 AM, Albert Y. C. Lai wrote:

As you probably suspect, one single use of buildExpressionParser  
cannot accomplish it. It is equivalent to the problem of  
homogeneous lists.


The issue is that I need buildExpressionParser to parse numerical  
expression but return logical ones, i.e.


data CondExpr
  = CondExpr Op NumExpr NumExpr

The way b-E-P is set up it wants NumExpr to be its return type and  
thus I cannot return a CondExpr. I'm still scratching my head but in  
all likehood I'll have to hack a custom version of b-E-P.


Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Parsec: buildExpressionParser of a different type than parsed term

2007-04-09 Thread Albert Y. C. Lai

Albert Y. C. Lai wrote:
However, you can make two uses of buildExpressionParser, one for numeric 
expressions and the other for logical expressions. Mutual reference is 
no problem since,


OK, I now see this is easier said than done in most common applications.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe