Better UX for "types with multiple roles" in the IDE #11366
Replies: 4 comments 20 replies
-
just throwing ideas out there to start the conversation:
|
Beta Was this translation helpful? Give feedback.
-
Giving an approximate library developer / end user spec:
|
Beta Was this translation helpful? Give feedback.
-
One of the (not yet properly formulated) use-cases is related to the interoperability between
If there is a |
Beta Was this translation helpful? Give feedback.
-
Thank you all for your comments. To demonstrate the desired state, let's consider following Enso module and its behavior in the IDE: from Standard.Base import all
import Standard.Visualization
type R
private V a:Text i:Integer
as_text self = self
as_both self = self
as_int self = self
Text.from (that:R) = that.a
Integer.from (that:R) = that.i
main =
n = R.V "Hi" 3
t1 = n.as_text
b2 = n.as_both
i3 = n.as_int first of all, there are some obvious problems in the current IDE:
but at the end I managed to negotiate and settle with the IDE on: from Standard.Base import all
import Standard.Visualization
type R
private V a:Text i:Integer
as_text self = self:Text
as_int_text self =
r = (self : Integer & Text)
r
as_text_int self =
r = (self : Text & Integer)
r
as_int self = self:Integer
Text.from (that:R) = that.a
Integer.from (that:R) = that.i
main =
n = R.V "Hi" 3
t1 = n.as_text
b2 = n.as_int_text
i3 = n.as_int
node1 = n.as_text_int with that code we can see that however |
Beta Was this translation helpful? Give feedback.
-
Using Enso Type Classes in the IDE
Types playing multiple roles are often represented by type classes in languages similar to Enso. Enso does support type classes on the runtime level:
Is there anything special on type class value?
type
with singleprivate
constructor taking two argumentsThe question however is: How to improve UX of obtaining such a type class?
from
conversionsRight now there is no special support for conversions in the IDE. Conversions are only used automatically when converting autoscoped constructors (#9285) and other argument types. However there is no explicit UI for that. This discussion is here to identify the necessary UI changes to make the conversions to type classes more usable for the needs of standard libraries.
TL;DR
The solution to the below listed use-cases is going to be built around values with intersection types and conversions. Such multi values are already present in the Enso runtime and it is just needed to expose them to the IDE properly. With proper information about intersection types of a value at hand and with already provided database of from conversions, the IDE shall be capable to handle all the use-cases.
Seeing All Conversion is possible as they are all listed in the suggestion DB. Preferred Conversions are those that are re-exported via library
Main
- e.g. those that get imported byfrom Standard.Xyz import all
- those are automatically offered to the user by exposing methods on the target types directly in the component browser (of course with some level of Auto-Domination) - more complicated conversions need to be explicitly imported before being used - IDE has to insert appropriateimport
statement when user selects (either as argument ofAny.to
method or by other means) such a conversion.Treat
Column
orVector
as aTable
is possible because there will be preferred conversions offering such simple metamorphosis. Treat single columnTable
as aColumn
will be handled at creation time by creating multi value representing both types at once - e.g. table as well as column. IDE uses the list of all types participating in value's intersection type to compose list of suitable methods to be displayed in the component browser.Remaining tasks
(multi_value : Table) : Column
to succeed #11482Use-Cases
Treat
Column
orVector
as aTable
There is a simple conversion from a
Column
toTable
and there is a simple conversions of aVector
to (unnamed)Column
. Can the IDE's component browser display methods of aTable
when one is working withColumn
orVector
object?Treat single column
Table
as aColumn
When there is a
Table
object with a singleColumn
it makes sense to treat it as both: as aTable
and as (the single)Column
. Can the IDE's component browser display methods of aTable
andColumn
in such a case? Can we prevent methods from aColumn
to be displayed in the component browser, when a table has zero or more than one column?Possible solution: described here.
Preferred Conversions
Currently there is one type class adhering to the blueprint:
Comparable
. A lot of classes is convertible to Comparable. However it may not be wise to showComparable
methods to the user as theComparable.from
conversion may not be that important.We need a way to specify which conversions should be included by default and to control what (methods from possible conversions) appears in the component browser.
Auto-Domination
The functions from the type classes that a value can be converted to should appear in the component browser in the normal way. When the instance has a method already with the same name that dominates (and only instance one should be shown).
Seeing All Conversion
By default the component browser shows only preferred conversion (see above). However there should be a way to see all the possible conversions.
Possible solution: there is method
Any.to
available on every object. When selected, the drop down widget shall offer all the conversions. However probably sorted by preference.Displaying Conversions
The IDE should identify to the user that a conversion (e.g. a cast like
op1 : Table
) may be needed to invoke certain method. The IDE should identify to the user that a conversion is taking place in the code graph - either explicitly or implicitly. There should be a way to analyze/navigate to the actual conversion that's taken a place.Beta Was this translation helpful? Give feedback.
All reactions