-- |Moves the turtle leaving a trail behind it.
move :: Turtle -> String -> Int -> IO Turtle
move t dir n
    | dir == "up"    = let (x,y) = loc t
                       in return $ t { loc   = (x,y+n)
                                     , image = draw_seg (x,y) (x,y+n) (color t)
                                               (image t)
                                     }
    | dir == "down"  = let (x,y) = loc t
                       in return $ t { loc   = (x,y-n)
                                     , image = draw_seg (x,y) (x,y-n) (color t)
                                               (image t)
                                     }
    | dir == "left"  = let (x,y) = loc t
                       in return  $ t { loc   = (x-n,y)
                                      , image = draw_seg (x,y) (x-n,y) (color t)
                                                (image t)
                                      }
    | dir == "right" = let (x,y) = loc t
                       in return  $ t { loc   = (x+n,y)
                                      , image = draw_seg (x,y) (x+n,y) (color t)
                                                (image t)
                                      }
    | otherwise      = error ("Parse error on line " ++ show (comln t)
                              ++ ": invalid direction: '" ++ dir ++ "'")
                       >> exitFailure >> nEW_TURTLE
move :: Turtle -> String -> Int -> IO Turtle
move t dir n
    | dir == "up"    = let (x,y) = loc t
                       in return $ t { loc   = (x,y+n)
                                     , image = draw_seg (x,y) (x,y+n) (color t)
                                               (image t)
                                     }
    | dir == "down"  = let (x,y) = loc t
                       in return $ t { loc   = (x,y-n)
                                     , image = draw_seg (x,y) (x,y-n) (color t)
                                               (image t)
                                     }
    | dir == "left"  = let (x,y) = loc t
                       in return  $ t { loc   = (x-n,y)
                                      , image = draw_seg (x,y) (x-n,y) (color t)
                                                (image t)
                                      }
    | dir == "right" = let (x,y) = loc t
                       in return  $ t { loc   = (x+n,y)
                                      , image = draw_seg (x,y) (x+n,y) (color t)
                                                (image t)
                                      }
    | otherwise      = error ("Parse error on line " ++ show (comln t)
                              ++ ": invalid direction: '" ++ dir ++ "'")
                       >> exitFailure >> nEW_TURTLE
move t dir n
    | dir == "up"    = let (x,y) = loc t
                       in return $ t { loc   = (x,y+n)
                                     , image = draw_seg (x,y) (x,y+n) (color t)
                                               (image t)
                                     }
    | dir == "down"  = let (x,y) = loc t
                       in return $ t { loc   = (x,y-n)
                                     , image = draw_seg (x,y) (x,y-n) (color t)
                                               (image t)
                                     }
    | dir == "left"  = let (x,y) = loc t
                       in return  $ t { loc   = (x-n,y)
                                      , image = draw_seg (x,y) (x-n,y) (color t)
                                                (image t)
                                      }
    | dir == "right" = let (x,y) = loc t
                       in return  $ t { loc   = (x+n,y)
                                      , image = draw_seg (x,y) (x+n,y) (color t)
                                                (image t)
                                      }
    | otherwise      = error ("Parse error on line " ++ show (comln t)
                              ++ ": invalid direction: '" ++ dir ++ "'")
                       >> exitFailure >> nEW_TURTLE