FP-style vs. OO-style AST structure

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

FP-style vs. OO-style AST structure

Doug Kirk
Hi,

I'm a Haskell newbie, but not new to programming, and I have a
question regarding style (I think).

I'm writing a parser for OMG's OCL, and have two ways of defining the
AST model of a constraint. Each constraint in OCL has the following 4
characteristics:

1. name :: Maybe String
2. context :: UmlElement
3. expr :: OclExpression
4. type :: OclConstraintType

Now, having come from an O-O background, this looks right; however, in
an FPL, it may not be. OclConstraintType is essentially an enumeration
of the values:

     Invariant
   | Precondition
   | Postcondition
   | InitialValue
   | Derivation
   | Body

The question is this: is it better to create a single type as above
with a 'type' attribute, or would it be better to use the types as
separate constructors of a Constraint, each constructor taking the
same attributes?

I'm looking to avoid any pitfalls that could occur with either
decision, and at this point I don't know the benefits of doing it one
way vs. the other.

BTW, I am using UUST Parser Combinator AG for the parser definition,
in case that makes a difference.

Thanks!
--doug

_______________________________________________
Haskell mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell