Re: A question about dynamic typing

Nick Name
Or maybe the subject has nothing to do with my question :)
It does, I think. <snip subject="class Visible"/>
My problem is: an user putting someway different "visible" elements in a list (wich could be represented in a side panel) will want to retrieve an object with its full type when clicking on it (to be able to perform specific applications), but this isn't allowed by the type system.
This does require dynamic, run-time typing (to make the cast safe). GHC has a dynamic typing library (for monomorphic types only, but I doubt that'll be an issue for you); it's in Data.Dynamic. Short version: if Typeable is a super-class of Visible or mentioned in your existential type (i.e., forall a. (Visible a, Typeable a) => Con) you can use (fromDynamic . toDyn) to safely (attempt to) convert the abstract type into the concrete one. If that last paragraph wasn't coherent, I can try to explain it more.
It's not a problem of functional programming: even in object oriented programming I see the same problem if one doesn't use some form of typecast.
Where am I wrong? Are there alternatives?
Vincenzo
Jon Cast

On Sun, 19 Jan 2003 12:50:16 -0600
Jon Cast
Short version: if Typeable is a super-class of Visible or mentioned in your existential type (i.e., forall a. (Visible a, Typeable a) => Con) you can use (fromDynamic . toDyn) to safely (attempt to) convert the abstract type into the concrete one. If that last paragraph wasn't coherent, I can try to explain it more.
Ok, this is clear. I am still not sure of how to decide the type to give to the "extracted" object. In the graphical interface, any object should have a menu saying on its top row: "Text file" or "Applet" (depending from the type of the object) and then a list of operations. This should happen even when the object is inside the panel-list, (so maybe a panel would be a list of untyped "objects" with an attribute of type [Operation]). But, to fully exploit the power of a "functionally-programmed" desktop, the interface should allow the user to map an operation onto all the objects of the panel; in this case the allowed operations should be those that all the object share. This is what I think, however I can't realize the connection between the haskell type system and what I wish to have. Can someone lead me to a clearer vision of the topic? Vincenzo -- First they ignore you, then they laugh at you, then they fight you, then you win. [Gandhi]
participants (2)
-
Jon Cast
-
Nick Name