I am trying to implement tortoise graphics in Haskell. The goal is to write a function like this:
draw_something = do forward 100 right 90 forward 100 ...
and then create a list of points (possibly with additional properties):
> draw_something (0,0) 0 -- start at (0,0) facing east (0 degrees) [(0,0), (0,100), (-100,100), ...]
Everything works fine for me, but I did not implement it as a Haskell Monad and used do-notation. Main code:
data State a = State (a, a) a
With this I can now write
> [initstate] `bind` (forward 100) `bind` (right (pi/2)) `bind` (forward 100) [State (0.0,0.0) 0.0,State (0.0,100.0) 0.0,State (0.0,100.0) 1.5707964,State (100.0,99.99999) 1.5707964]
And get the expected result. However, I cannot make this an instance of Monad .
instance Monad [State] where ...
leads to
`State' is not applied to enough type arguments Expected kind `*', but `State' has kind `* -> *' In the instance declaration for `Monad [State]'
And if I move the list to a new object
data StateList a = StateList [State a] instance Monad StateList where return x = StateList [x]
I get
Couldn't match type `a' with `State a' `a' is a rigid type variable bound by the type signature for return :: a -> StateList a at logo.hs:38:9 In the expression: x In the first argument of `StateList', namely `[x]' In the expression: StateList [x]
I tried different versions, but I never started it as I would like. What am I doing wrong? What do I misunderstand?