How to re-export data type from functor argument in standard ML

Is it possible in standard ML to re-export data type constructors that are part of the structure obtained as a functor argument. Some code will probably simplify this understanding:

signature FLAG =
  sig
    type t
  end

signature MEMBER =
  sig
    structure Flag : FLAG
  end

functor Member(F : FLAG) : MEMBER =
  struct
    structure Flag = F
  end

structure M =
  Member(struct
    datatype t =
      FLAG_1
    | FLAG_2
  end)

val flag1 = M.Flag.FLAG_1;
(* Error: unbound variable or constructor: FLAG_1 in path M.Flag.FLAG_1 *)

The above example may not make any practical sense, but it is just a water problem that I encountered in one of my projects.

+4
source share
1 answer

If I understand the situation correctly, the specification of the unfinished type in the signature FLAGimplies that it tremains opaque and, therefore, inaccessible to anything outside the structures that implement it FLAG.

, SML, , , , , . , , , , , ; , , . type t: , , .

, , , , . .

signature FLAG =
sig
    datatype t = FLAG_1 | FLAG_2
end

signature MEMBER =
sig
    structure Flag : FLAG
end

functor Member(F : FLAG) : MEMBER =
struct
    structure Flag = F
end

structure M =
Member(struct
        datatype t =
                 FLAG_1
               | FLAG_2
        end)

- val a = M.Flag.FLAG_1;
val a = FLAG_1 : ?.t

, , : , FLAG, , , functor Member. , , :

signature FLAG =
sig
    type t
end

structure F : FLAG =
struct
    datatype t =
             FLAG_1
           | FLAG_2
end

[opening ~/Programming/sml/scratch/scratch.sml]
signature FLAG = sig type t end
structure F : FLAG
val it = () : unit
- F.FLAG_1;
stdIn:63.1-63.9 Error: unbound variable or constructor: FLAG_1 in path F.FLAG_1
+4

Source: https://habr.com/ru/post/1656269/


All Articles