2016-08-03 31 views
1
module type FOOable = sig 
    type 'a t 
    val foo : 'a -> 'a t 
end 

module type FOO_FUCNTOR = 
    functor (Elt : FOOable) -> 
    sig 
     type 'a t 
     val foo_alias : 'a -> 'a t 
     (* ... *) 
    end 

Wie kann ich auf die Art beziehen 'a t definiert durch FOOable da es nicht möglich ist Elt.t zu benutzen?OCaml functors und Typ Themen

So in diesem Beispiel wäre es geworden type 'a t = 'a list

module MakeFoo : FOO_FUNCTOR = 
    functor (Elt : FOOable) -> 
    struct 
    type 'a t = ??? (* I want the type 'a t belonging to Elt *) 
    let foo_alias = Elt.foo 
    end 

module FooableList = struct 
    type = 'a list 
    let foo x = [x] 
end 

module FooList = MakeFoo(FooableList) 

let a = FooList.foo_alias 2 

Antwort

4

Sie einfach 'a Elt.t eingeben können, und Sie werden sicher sein, die richtige Art zu verweisen.

module MakeFoo : FOO_FUNCTOR = 
    functor (Elt : FOOable) -> 
    struct 
    type 'a t = 'a Elt.t 
    let foo_alias = Elt.foo 
    end 

Beachten Sie, dass wie in der Definition von FOO_FUNCTOR, die Art Gleichheit verborgen ist, wird die Verbindung zwischen 'a t und 'a Elt.t nicht außerhalb der MakeFOO Definition sichtbar sein (aber das kann sein, was Sie suchen).