You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Peut-être est-ce parce-que je n'utilise pas énormément les objets, je trouve
souvent cela plus simple quand je veux un alias pour un petit type objet de
créer un type plutôt qu'un type de classe. Ceci est toutefois limité quand le
type et l'application grandissent : on est alors obligé d'écrire toutes les
methodes à chaque foi, alors qu'avec un type de classe, on peut hérité des
classes précédament définies.
Ne serait il pas possible de faire avec les types objets commes avec les
variants polymorphes ? ie quelque chose comme :
type obj_simple = < foo : int; bar : float >
type obj2 = < obj_simple; toto : int >
The text was updated successfully, but these errors were encountered:
Not exactly the same request, but I think it could be useful to refer to a class type in an inline object type. Currently, there is no real clean way to reuse class type for constraining the type of a function.
For instance,
class type foo =
object
method foo: int
end
class type bar =
object
method bar: int
end
It's possible to do that:
class f (x:'a) =
object
constraint 'a = #foo
constraint 'a = #bar
method apply = x # bar + x # foo
end
which have type:
class f: 'a ->
object
constraint 'a = #foo
constraint 'a = #bar
method apply: int
end
But it is not possible to write something like that:
let f x = x # foo + x # bar
with type of f being something else than
val f: < foo: int; bar: int; .. > -> int
Unless I am mistaken, the only way to have a clean interface is to define another class type which combines foo and bar like this
class type foobar =
object
inherit foo
inherit bar
end
and then we can write
val f: #foobar -> int
But this scales badly since this means we need to define 2^n interface if we have n basic class types (and also invent 2^n relevant class names)
Maybe allow to write something like
val f: #foo & #bar -> int
I guess the difficult thing is to find a syntax to express this :)
Original bug ID: 3369
Reporter: administrator
Assigned to: @Octachron
Status: resolved (set by @Octachron on 2018-01-10T18:19:31Z)
Resolution: fixed
Priority: normal
Severity: feature
Category: typing
Monitored by: lavi
Bug description
Full_Name: Laurent Vibert
Version: 3.08
OS:
Submission from: 194.98.128.33 (194.98.128.33)
Bonjour,
Peut-être est-ce parce-que je n'utilise pas énormément les objets, je trouve
souvent cela plus simple quand je veux un alias pour un petit type objet de
créer un type plutôt qu'un type de classe. Ceci est toutefois limité quand le
type et l'application grandissent : on est alors obligé d'écrire toutes les
methodes à chaque foi, alors qu'avec un type de classe, on peut hérité des
classes précédament définies.
Ne serait il pas possible de faire avec les types objets commes avec les
variants polymorphes ? ie quelque chose comme :
type obj_simple = < foo : int; bar : float >
type obj2 = < obj_simple; toto : int >
The text was updated successfully, but these errors were encountered: