haskell - Design a drawing api for Canvas -
i adding function threepenny ui api. had ability draw line canvas.
the function can write have following signature:
moveto :: vector -> ui () lineto :: vector -> ui () stroke :: ui () strokestyle :: ui () beginpath :: ui ()
each primitive moveto
, lineto
should happen in between beginpath
.. stroke call. how enforce beginpath
... stroke sequence. design give user no choice drawing lines. user not aware of beginpath
... stroke sequence.
here's how design canvas api.
newtype drawing = ... instance monoid drawing ... -- combining drawings line :: vector -> vector -> drawing path :: [vector] -> drawing withstyle :: style -> drawing -> drawing rundrawing :: drawing -> ui ()
here functions operate on semantically meaningful objects (from user's perspective), rather imperative commands. should implementable type
newtype drawing = drawing (ui ())
however subtleties require type have bit more structure, open (e.g. something -> ui ()
).
Comments
Post a Comment