module Wumpus.Drawing.Turtle.TurtleClass
(
Coord
, TurtleM(..)
, setsLoc
, setsLoc_
, resetLoc
, moveLeft
, moveRight
, moveUp
, moveDown
, nextLine
) where
type Coord = (Int,Int)
class Monad m => TurtleM m where
getLoc :: m (Int,Int)
setLoc :: (Int,Int) -> m ()
getOrigin :: m (Int,Int)
setOrigin :: (Int,Int) -> m ()
setsLoc :: TurtleM m => (Coord -> (a,Coord)) -> m a
setsLoc f = getLoc >>= \coord ->
let (a,coord') = f coord in setLoc coord' >> return a
setsLoc_ :: TurtleM m => (Coord -> Coord) -> m ()
setsLoc_ f = getLoc >>= \coord -> setLoc (f coord)
resetLoc :: TurtleM m => m ()
resetLoc = getOrigin >>= setLoc
moveRight :: TurtleM m => m ()
moveRight = setsLoc_ $ \(x,y)-> (x+1, y)
moveLeft :: TurtleM m => m ()
moveLeft = setsLoc_ $ \(x,y) -> (x1,y)
moveUp :: TurtleM m => m ()
moveUp = setsLoc_ $ \(x,y) -> (x,y+1)
moveDown :: TurtleM m => m ()
moveDown = setsLoc_ $ \(x,y) -> (x ,y1)
nextLine :: TurtleM m => m ()
nextLine = getOrigin >>= \(ox,_) ->
setsLoc_ $ \(_,y) -> (ox,y1)