[Haskell-cafe] mapping a concept to a type

Corentin Dupont corentin.dupont at gmail.com
Fri May 18 20:52:00 CEST 2012

Hi everybody,
I'm still working on implementing a nomic game in Haskell.
Although the game is pretty advanced, I'm still confused by one fundamental
A nomic game is composed of rules.
A Rule is a sort of little program submitted by the player during the game.
They come in two fashions:
- a Normal rule, when executed, can change the state of the Game.
- a Meta rule, when executed on another rule, can assess the legality of
that rule and change the state of the Game.

In those definitions, the Game can be seen as a data structure containing
all the current state of the game. Sorry if it's a bit abstract, but as
it's fairly complex,
I'd prefer to keep it like this for the moment.
Thus, I found that those definitions can be translated to two possible type

type NormalRule = State Game ()
type MetaRule = Rule -> State Game Bool
data Rule = MR MetaRule | NR NormalRule

*** or ***

newtype Rule = Rule {rule :: Maybe Rule -> (State Game Bool)}

All rules submitted by the user must be of the type Rule. It is thus
important that it is very clean.
Which type do you prefer?
I find both heavy and redundant. The first forces me to specify if I want
an argument of not (with the constructors MR and NR), the second forces me
to pass the Nothing argument in the case of a Normal rule, and to return a
dummy value (for ex. return True).
Do you know of a construction/abstraction that allows having or not an
argument (a variable number of arguments, here zero or one)?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120518/f85c62d4/attachment.htm>

More information about the Haskell-Cafe mailing list