Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Haskell
Wiki community
Recent changes
Random page
HaskellWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Diagrams/Dev/Expression
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Static typing == This is the approach currently taken. Each backend has a "token type" and must implement instances of the form <code>Renderable Prim Backend</code>. Prims get wrapped up in an existential wrapper along with an appropriate <code>Renderable</code> instance. When a backend goes to render some primitives, it just unwraps them and uses the enclosed <code>Renderable</code> instance; it doesn't even need to know what type they are. This does mean, however, that the backend type ''must'' show up as a parameter to the <code>Diagram</code> type---otherwise the existentially quanitifed <code>Renderable</code> instances would be useless, as there would be no way to know which backend they are for! However, this also makes sense, in a way. If a diagram has type <code>Diagram Foo R2</code>, then we know statically that it can only contain primitives which can be rendered by backend Foo---because any primitive of type <code>P</code> must be wrapped up with a <code>Renderable P Foo</code> instance, and the only way to obtain such an instance is if it is provided by the backend. More generally, diagrams can be given polymorphic types like <code>(Backend b R2, Renderable (Path R2) b, Renderable Image b) => Diagram b R2</code> with one constraint for each different type of primitive contained in the diagram. === Pros === * Rendering will never fail at runtime. We know statically that if it typechecks to give a certain diagram to a certain backend, the backend knows what to do with all the primitives it contains. * Behavior is more transparent to users: if it typechecks, it will work as expected. === Cons === * The backend type parameter ends up "infecting" quite a lot of types, including UpAnnots, DownAnnots, QDiagram, QDiaLeaf, Subdiagram, SubMap, Prim, DNode, DTree, RNode, RTree. * If users want to give type signatures to their diagrams, they have to either write some complicated polymorphic type with lots of constraints, or tie their diagram to a specific backend (or use the <code>B</code> hack, which sort of works, but is not perfect---e.g. it makes it hard to use multiple backends at once).
Summary:
Please note that all contributions to HaskellWiki are considered to be released under simple permissive license (see
HaskellWiki:Copyrights
for details). If you don't want your writing to be edited mercilessly and redistributed at will, then don't submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
DO NOT SUBMIT COPYRIGHTED WORK WITHOUT PERMISSION!
Cancel
Editing help
(opens in new window)
Toggle limited content width