Ich mag würde eine Schnittstelle PROPERTY
und mindestens 2 Module Type
und Formula
es passend zu definieren:Ein Design von Modulen und Schnittstelle
module type PROPERTY =
sig
type t
val top : t
val bot : t
val to_string: t -> string
val union: t -> t -> t
val intersection: t -> t -> t
end
module Type = (struct
type t =
| Tbot
| Tint
| Tbool
| Ttop
...
end: PROPERTY)
module Formula = (struct
type t =
| Fbot
| Ftop
| Fplus of int * Type.t
...
let union =
... Type.union ...
...
end: PROPERTY)
Es gibt zwei Anforderungen:
1) Ich möchte die Konstruktoren von Type
können außerhalb aufgerufen werden (alle Programme, falls erforderlich)
2) Ein Teil einiger Werte von enthält Werte von Types
, zum Beispiel ist Fplus (5, Type.Tint)
vom Typ Formula
; auch einige Funktionen von Formula
müßten einige Funktionen von Type
, zum Beispiel nennen, muss Formula.union
nennen Type.union
Könnte mir jemand sagen, wie die Erklärung oben zu ändern, um meine Anforderungen zu erfüllen? Zusätzliche Module können bei Bedarf hinzugefügt werden ...
Drive-by Kommentar (orthogonal ist Gasche eine Antwort) : Sie können Deklarationen mit einer Signatur ascription bequem als 'Modul X: SIG = ...' schreiben. –