Hi folks,I just wrote this:import Diagrams.Preludeimport Diagrams.Backend.Cairotype Dia = Diagram Cairo R2class Turtlish t wherepic :: t s -> Diastate :: t s -> smove :: s -> t s -> t s(>>>),(+++) :: t s -> t s -> t sx >>> y = x +++ move (state x) y
The idea is that s is a turtle state, t s contains such a state along with a growing diagram, and >>> superimposes the diagrams after shuffling the right hand t s around according to the s I extract from the left hand t s.But I have different turtles planned. I want a regular turtle, a Sankey turtle which also has a width, and we could imagine sub-turtles that only had the angle or only the position. But in all cases, I think the above class describes how I want to compose diagrams together. I already tried it with monads but I'm now thinking that I want something like the above instead of a monad.So how do I use it to make a regular turtle? Maybe something like:data TurtState = TurtState P2 CircleFracdata TurtWorld s = TurtWorld Dia sI know exactly what s is above but otherwise the kinds don't match below.instance Turtlish TurtWorld wherepic (TurtWorld d _) = dstate (TurtWorld _ s) = s(TurtWorld d1 _) +++ (TurtWorld d2 s2) =TurtWorld (d1 `atop` d2) s2move (pp,aa) (TurtWorld d (p,a)) = TurtWorld(d # rotate aa # translate pp)( (p # rotate aa + pp) , (a+aa) )
Naturally, it barfs over move saying:Couldn't match type `s' with `(R2, t0)'`s' is a rigid type variable bound bythe type signature for move :: s -> TurtWorld s -> TurtWorld sat turtle.hs:20:3In the pattern: (pp, aa)In an equation for `move':move (pp, aa) (TurtWorld d (p, a))= TurtWorld(d # rotate aa # translate pp) ((p # rotate aa + pp), (a + aa))In the instance declaration for `Turtlish TurtWorld'because it hasn't a clue what (pp,aa) is and wants s totally generic anyway.But what am I supposed to do instead? Isn't it an everyday thing to use a generic pattern with a specific type?TIA,Adrian.