[Haskell-cafe] mapping a concept to a type
Corentin Dupont
corentin.dupont at gmail.com
Sat May 19 01:06:26 CEST 2012
Yes I totally agree, they have different kind. A Normal Rule is *
whereas a Meta Rule is * -> *.
But I have no experience with typeclasses. That could be what I'm looking for!
What they have in common? Well, Id' say that a rule (whatever sort it is) can:
- change the state of the game when executed - hence the State Transformer
- perhaps assess the legality of *something* (including the legality
of another rule)
So this gives:
class (Monad r) => (Rule r) where
changeState :: StateT Game r ()
legal :: l -> r Bool
legal _ = return True
Does that sound good? I will continue experiment with it tomorrow.
My other comment inline:
On Sat, May 19, 2012 at 12:02 AM, Ben Doyle
<benjamin.peter.doyle at gmail.com> wrote:
>
> I wonder if you want a typeclass here, rather than a type? A Normal Rule is pretty much a State Transformer, while a Meta Rule seems like a higher-order function on Normal Rules[*]. These are different kinds of things --- and I say "kind" advisedly --- so perhaps better to define the specific commonalities you need than to try to shoehorn them both into one type.
>
> [*]: Possibly related question: Can a Meta Rule depend upon an implementation detail of a Normal rule?
That's a very good question. I think the answer is yes.
In other words, does
> rule1 g == rule2 g
> imply
> myMetaRule rule1 == myMetaRule rule2
>
> ?
So this does not hold. Here myMetaRule is analysing the legality of
rule1, possibly analysing the code of rule1 (quite simply for now).
(To make thinks clear, the type of "myMetaRule rule1" is a monadic boolean).
Thanks!
Corentin
More information about the Haskell-Cafe
mailing list