Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0003369OCamlOCaml typingpublic2004-12-15 17:362017-01-06 10:16
Reporteradministrator 
Assigned To 
PrioritynormalSeverityfeatureReproducibilityalways
StatusacknowledgedResolutionopen 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0003369: feature wish : heritage dans les types objets
DescriptionFull_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 >

TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0017082)
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 =
  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 :)


- 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


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker