Did you know you can write

1
let FormatFireball (Nonterminal.Firebal(name, damages)) = ...

Moreover, your discriminated union looks a bit flat. What about

1
2
3
4
5
6
7
type Round = Round of int * ActionOrFollowup list
and ActionOrFollowup =
| Action of ...
| Followup of Exertion
and Exertion =
| ExertionOK of ...
| ExertionFail of ...

and so on...
The union should match your grammar, I don't understand why that's difficult.

By on 9/1/2011 7:44 AM ()

Followup: after some thought, it seems likely that discriminated unions are probably the root cause of the problem here. My current plan for refactoring is to promote Round, Fireball, etc. to concrete classes in OO style (CFG productions will be expressed as different ctors, e.g. Fireball(TakeDamage list)). The nice thing about discriminated unions is that they are automatically compatible with patterns--but in F# I can just define corresponding active patterns for each concrete class.

I may post more details after I get it working but that's the basic notion.

-Max

By on 8/31/2011 10:26 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper