[MLton-commit] r6536
Matthew Fluet
fluet at mlton.org
Mon Apr 7 11:33:11 PDT 2008
Functor to abstract a representation of a type.
A number of the system types (e.g., Posix.FileSys.file_desc) are not
abstracted, due to the fact that they are defined as follows:
structure C_Int = struct open Int32 type t = int end
structure C_Fd = C_Int
structure PosixIO = struct
...
type file_desc = C_Fd.t
...
end
signature BASIS_EXTRA = sig
...
end
(* Types referenced in signatures by structure name *)
where Posix.IO.file_desc = Posix.IO.file_desc
This reveals that Posix.IO.file_desc is equal to Int32.int.
This commit introduces a functor to abstract the representation of a
type, to be used to elimate the type leakage described above.
----------------------------------------------------------------------
U mlton/trunk/basis-library/build/sources.mlb
A mlton/trunk/basis-library/util/abs-rep.fun
A mlton/trunk/basis-library/util/abs-rep.sig
----------------------------------------------------------------------
Modified: mlton/trunk/basis-library/build/sources.mlb
===================================================================
--- mlton/trunk/basis-library/build/sources.mlb 2008-04-07 07:39:22 UTC (rev 6535)
+++ mlton/trunk/basis-library/build/sources.mlb 2008-04-07 18:33:10 UTC (rev 6536)
@@ -212,6 +212,8 @@
../util/unique-id.fun
../util/cleaner.sig
../util/cleaner.sml
+ ../util/abs-rep.sig
+ ../util/abs-rep.fun
../config/c/sys-types.sml
../system/pre-os.sml
Added: mlton/trunk/basis-library/util/abs-rep.fun
===================================================================
--- mlton/trunk/basis-library/util/abs-rep.fun 2008-04-07 07:39:22 UTC (rev 6535)
+++ mlton/trunk/basis-library/util/abs-rep.fun 2008-04-07 18:33:10 UTC (rev 6536)
@@ -0,0 +1,34 @@
+(* Copyright (C) 2008 Henry Cejtin, Matthew Fluet, Suresh
+ * Jagannathan, and Stephen Weeks.
+ *
+ * MLton is released under a BSD-style license.
+ * See the file MLton-LICENSE for details.
+ *)
+
+functor MkAbsRep(type rep) :> ABS_REP where type Rep.t = rep =
+ struct
+ structure Rep = struct type t = rep end
+ type t = Rep.t
+ val arrayFromRep : rep array -> t array = fn x => x
+ val arrayToRep : t array -> rep array = fn x => x
+ val fromRep : rep -> t = fn x => x
+ val listFromRep : rep list -> t list = fn x => x
+ val listToRep : t list -> rep list = fn x => x
+ val toRep : t -> rep = fn x => x
+ val vectorFromRep : rep vector -> t vector = fn x => x
+ val vectorToRep : t vector -> rep vector = fn x => x
+ end
+
+functor MkAbsRepEq(eqtype rep) :> ABS_REP_EQ where type Rep.t = rep =
+ struct
+ structure Rep = struct type t = rep end
+ type t = Rep.t
+ val arrayFromRep : rep array -> t array = fn x => x
+ val arrayToRep : t array -> rep array = fn x => x
+ val fromRep : rep -> t = fn x => x
+ val listFromRep : rep list -> t list = fn x => x
+ val listToRep : t list -> rep list = fn x => x
+ val toRep : t -> rep = fn x => x
+ val vectorFromRep : rep vector -> t vector = fn x => x
+ val vectorToRep : t vector -> rep vector = fn x => x
+ end
Added: mlton/trunk/basis-library/util/abs-rep.sig
===================================================================
--- mlton/trunk/basis-library/util/abs-rep.sig 2008-04-07 07:39:22 UTC (rev 6535)
+++ mlton/trunk/basis-library/util/abs-rep.sig 2008-04-07 18:33:10 UTC (rev 6536)
@@ -0,0 +1,34 @@
+(* Copyright (C) 2008 Henry Cejtin, Matthew Fluet, Suresh
+ * Jagannathan, and Stephen Weeks.
+ *
+ * MLton is released under a BSD-style license.
+ * See the file MLton-LICENSE for details.
+ *)
+
+signature ABS_REP =
+ sig
+ type t
+ structure Rep : sig type t end
+ val arrayFromRep : Rep.t array -> t array
+ val arrayToRep : t array -> Rep.t array
+ val fromRep : Rep.t -> t
+ val listFromRep : Rep.t list -> t list
+ val listToRep : t list -> Rep.t list
+ val toRep : t -> Rep.t
+ val vectorFromRep : Rep.t vector -> t vector
+ val vectorToRep : t vector -> Rep.t vector
+ end
+
+signature ABS_REP_EQ =
+ sig
+ eqtype t
+ structure Rep : sig eqtype t end
+ val arrayFromRep : Rep.t array -> t array
+ val arrayToRep : t array -> Rep.t array
+ val fromRep : Rep.t -> t
+ val listFromRep : Rep.t list -> t list
+ val listToRep : t list -> Rep.t list
+ val toRep : t -> Rep.t
+ val vectorFromRep : Rep.t vector -> t vector
+ val vectorToRep : t vector -> Rep.t vector
+ end
More information about the MLton-commit
mailing list