Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature wish : heritage dans les types objets #3369

Closed
vicuna opened this issue Dec 15, 2004 · 2 comments
Closed

feature wish : heritage dans les types objets #3369

vicuna opened this issue Dec 15, 2004 · 2 comments

Comments

@vicuna
Copy link

vicuna commented Dec 15, 2004

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 >

@vicuna
Copy link
Author

vicuna commented Jan 6, 2017

Comment author: @sbriais

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 :)

@vicuna
Copy link
Author

vicuna commented Jan 10, 2018

Comment author: @Octachron

This feature wish was granted in OCaml 4.06 with #1118 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants