-
Notifications
You must be signed in to change notification settings - Fork 43
Closed
Labels
Description
We should look into adding a Typeable
constraint, in order to be able to cast things out of Prim
wrappers. On the one hand, one could argue that you "shouldn't do that" and that you could just write a backend... but that's probably a pretty weak argument (it's impossible to predict how people will want to use diagrams) and adding a Typeable
constraint and some convenience functions for extracting primitives from diagrams wouldn't actually be very difficult.
Relevant IRC conversation:
(07:03) < gordon88> Hi all! let x = foobar :: Prim NullBackend R2. I know it's a Path R2. How do I extract the path from the Prim with an ordinary function?
(07:05) < gordon88> writing a backend instance just for extracting the content of a primitive sounds insane to me
(07:09) < gordon88> so I'd like to have something like a cast, is it possible in spite of the wall of typeclass-maddness that is going on?
(07:38) < fryguybob> gordon88: What are you doing that is forcing the type of foobar to be Prim?
(07:40) < gordon88> foobar d = (prims d !! 0) (but with a transform thrown in)
(07:41) < fryguybob> gordon88: Perhaps you could make the parameter d be something PathLike instead of a Diagram?
(07:42) < gordon88> basically, would just like to map prims to a more deeply embedded format, suitable for further processing. I'll investigate that
(07:42) < fryguybob> gordon88: By the way we do want to allow for more interesting queries on diagrams that should let you extract specific parts of the diagram.
(07:43) < fryguybob> gordon88: If that is the case, perhaps you really do want to write a backend.
(07:43) < fryguybob> gordon88: It isn't too complicated.
(07:44) < gordon88> yes, that's what I had to do and did. but it's a bit insane
(07:45) < gordon88> (conceptually really ugly imho)
(07:47) < fryguybob> gordon88: Sure. I think we could provide some sort of extractPaths :: Diagram b v -> Path v which gives absolute paths in order and ignores the styles.