Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0003369OCamltypingpublic2004-12-15 17:362018-01-10 19:19
Assigned Tooctachron 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0003369: feature wish : heritage dans les types objets
DescriptionFull_Name: Laurent Vibert
Version: 3.08
Submission from: (


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 >

TagsNo tags attached.
Attached Files

- Relationships

-  Notes
sbriais (reporter)
2017-01-06 10:16
edited on: 2017-01-06 10:18

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 =
    method foo: int

class type bar =
    method bar: int

It's possible to do that:

class f (x:'a) =
    constraint 'a = #foo
    constraint 'a = #bar
    method apply = x # bar + x # foo

which have type:

class f: 'a ->
    constraint 'a = #foo
    constraint 'a = #bar
    method apply: int

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 =
    inherit foo
    inherit bar

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

octachron (developer)
2018-01-10 19:19

This feature wish was granted in OCaml 4.06 with [^] .

- Issue History
Date Modified Username Field Change
2005-11-18 10:13 administrator New Issue
2016-12-07 17:33 shinwell Category OCaml general => OCaml typing
2016-12-07 17:33 shinwell Description Updated View Revisions
2017-01-06 10:16 sbriais Note Added: 0017082
2017-01-06 10:17 sbriais Note Edited: 0017082 View Revisions
2017-01-06 10:18 sbriais Note Edited: 0017082 View Revisions
2017-02-23 16:45 doligez Category OCaml typing => typing
2018-01-10 19:19 octachron Note Added: 0018821
2018-01-10 19:19 octachron Status acknowledged => resolved
2018-01-10 19:19 octachron Resolution open => fixed
2018-01-10 19:19 octachron Assigned To => octachron

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker