[MLton-commit] r5544
Vesa Karvonen
vesak at mlton.org
Sun May 6 00:32:42 PDT 2007
INTEGER in terms of concepts (although there is room for a few numeric
concepts).
----------------------------------------------------------------------
U mltonlib/trunk/com/ssh/extended-basis/unstable/detail/concept/mk-bounded.fun
U mltonlib/trunk/com/ssh/extended-basis/unstable/detail/ml/smlnj/sigs.cm
U mltonlib/trunk/com/ssh/extended-basis/unstable/detail/numeric/mk-integer-ext.fun
U mltonlib/trunk/com/ssh/extended-basis/unstable/extensions.mlb
U mltonlib/trunk/com/ssh/extended-basis/unstable/public/concept/formattable.sig
A mltonlib/trunk/com/ssh/extended-basis/unstable/public/concept/intable.sig
A mltonlib/trunk/com/ssh/extended-basis/unstable/public/concept/largeable.sig
A mltonlib/trunk/com/ssh/extended-basis/unstable/public/concept/wordable.sig
U mltonlib/trunk/com/ssh/extended-basis/unstable/public/export/common.sml
U mltonlib/trunk/com/ssh/extended-basis/unstable/public/numeric/integer.sig
----------------------------------------------------------------------
Modified: mltonlib/trunk/com/ssh/extended-basis/unstable/detail/concept/mk-bounded.fun
===================================================================
--- mltonlib/trunk/com/ssh/extended-basis/unstable/detail/concept/mk-bounded.fun 2007-05-01 22:00:01 UTC (rev 5543)
+++ mltonlib/trunk/com/ssh/extended-basis/unstable/detail/concept/mk-bounded.fun 2007-05-06 07:32:40 UTC (rev 5544)
@@ -9,3 +9,12 @@
type bounded_ex = bounded
val (minValue, maxValue) = bounds
end
+
+functor MkMaybeBounded (Core : MAYBE_BOUNDED_CORE) : MAYBE_BOUNDED = struct
+ open Core
+ type bounded_ex = bounded
+ val (minValue, maxValue) =
+ case bounds of
+ NONE => (NONE, NONE)
+ | SOME (min, max) => (SOME min, SOME max)
+end
Modified: mltonlib/trunk/com/ssh/extended-basis/unstable/detail/ml/smlnj/sigs.cm
===================================================================
--- mltonlib/trunk/com/ssh/extended-basis/unstable/detail/ml/smlnj/sigs.cm 2007-05-01 22:00:01 UTC (rev 5543)
+++ mltonlib/trunk/com/ssh/extended-basis/unstable/detail/ml/smlnj/sigs.cm 2007-05-06 07:32:40 UTC (rev 5544)
@@ -15,13 +15,17 @@
../../../public/concept/cstringable.sig
../../../public/concept/equality.sig
../../../public/concept/flags.sig
+ ../../../public/concept/formattable.sig
../../../public/concept/func.sig
+ ../../../public/concept/intable.sig
+ ../../../public/concept/largeable.sig
../../../public/concept/monad.sig
../../../public/concept/ordered.sig
../../../public/concept/scannable.sig
../../../public/concept/shiftable.sig
../../../public/concept/signed.sig
../../../public/concept/stringable.sig
+ ../../../public/concept/wordable.sig
../../../public/control/exit.sig
../../../public/control/exn.sig
../../../public/control/with.sig
Modified: mltonlib/trunk/com/ssh/extended-basis/unstable/detail/numeric/mk-integer-ext.fun
===================================================================
--- mltonlib/trunk/com/ssh/extended-basis/unstable/detail/numeric/mk-integer-ext.fun 2007-05-01 22:00:01 UTC (rev 5543)
+++ mltonlib/trunk/com/ssh/extended-basis/unstable/detail/numeric/mk-integer-ext.fun 2007-05-06 07:32:40 UTC (rev 5544)
@@ -5,16 +5,44 @@
*)
functor MkIntegerExt (I : BASIS_INTEGER) : INTEGER = struct
- open I
- type t = int
- val embString = (toString, fromString)
- val isoInt = (toInt, fromInt)
- val isoLarge = (toLarge, fromLarge)
- fun isZero i = fromInt 0 = i
- fun isEven i = isZero (rem (i, fromInt 2))
- val isOdd = not o isEven
- val bounds = case (minInt, maxInt) of
- (NONE, NONE) => NONE
- | (SOME min, SOME max) => SOME (min, max)
- | _ => raise Fail "impossible"
+ structure Core = struct
+ open I
+ type t = int
+ type bounded = t
+ type formattable = t
+ type formattable_format = BasisStringCvt.radix
+ type intable = t
+ type largeable = t
+ type largeable_large = BasisLargeInt.int
+ type ordered = t
+ type scannable = t
+ type scannable_format = formattable_format
+ type signed = t
+ type stringable = t
+ val zero = fromInt 0
+ fun signBit (x:t) = x < zero
+ fun copySign (x, y) = if sameSign (x, y) then x else ~x
+ val embString = (toString, fromString)
+ val isoInt = (toInt, fromInt)
+ val isoLarge = (toLarge, fromLarge)
+ val isoLargeInt as (toLargeInt, fromLargeInt) = isoLarge
+ fun isZero i = zero = i
+ fun isEven i = isZero (rem (i, fromInt 2))
+ val isOdd = not o isEven
+ val bounds =
+ case (minInt, maxInt) of
+ (NONE, NONE) => NONE
+ | (SOME min, SOME max) => SOME (min, max)
+ | _ => raise Fail "illegal"
+ end
+
+ structure MaybeBounded = MkMaybeBounded (Core)
+ structure Ordered = MkOrdered (Core)
+ structure Stringable = MkStringable (Core)
+
+ open MaybeBounded
+ open Ordered
+ open Stringable
+
+ open Core
end
Modified: mltonlib/trunk/com/ssh/extended-basis/unstable/extensions.mlb
===================================================================
--- mltonlib/trunk/com/ssh/extended-basis/unstable/extensions.mlb 2007-05-01 22:00:01 UTC (rev 5543)
+++ mltonlib/trunk/com/ssh/extended-basis/unstable/extensions.mlb 2007-05-06 07:32:40 UTC (rev 5544)
@@ -52,13 +52,18 @@
public/concept/equality.sig
public/concept/flags.sig
public/concept/func.sig
+ public/concept/intable.sig
+ public/concept/largeable.sig
public/concept/monad.sig
public/concept/ordered.sig
public/concept/scannable.sig
public/concept/shiftable.sig
public/concept/signed.sig
public/concept/stringable.sig
+ public/concept/wordable.sig
+ public/concept/formattable.sig
+
(* MkBounded *)
detail/concept/mk-bounded.fun
Modified: mltonlib/trunk/com/ssh/extended-basis/unstable/public/concept/formattable.sig
===================================================================
--- mltonlib/trunk/com/ssh/extended-basis/unstable/public/concept/formattable.sig 2007-05-01 22:00:01 UTC (rev 5543)
+++ mltonlib/trunk/com/ssh/extended-basis/unstable/public/concept/formattable.sig 2007-05-06 07:32:40 UTC (rev 5544)
@@ -4,12 +4,16 @@
* See the LICENSE file or http://mlton.org/License for details.
*)
+(** == Formattable == *)
+
signature FORMATTABLE = sig
type formattable
type formattable_format
val fmt : formattable_format -> formattable -> String.t
end
+(** == Formattable and Scannable == *)
+
signature FORMATTABLE_and_SCANNABLE = sig
include FORMATTABLE SCANNABLE
sharing type scannable = formattable
Added: mltonlib/trunk/com/ssh/extended-basis/unstable/public/concept/intable.sig
===================================================================
--- mltonlib/trunk/com/ssh/extended-basis/unstable/public/concept/intable.sig 2007-05-01 22:00:01 UTC (rev 5543)
+++ mltonlib/trunk/com/ssh/extended-basis/unstable/public/concept/intable.sig 2007-05-06 07:32:40 UTC (rev 5544)
@@ -0,0 +1,20 @@
+(* Copyright (C) 2007 SSH Communications Security, Helsinki, Finland
+ *
+ * This code is released under the MLton license, a BSD-style license.
+ * See the LICENSE file or http://mlton.org/License for details.
+ *)
+
+(** == Intable ==
+ *
+ * Intables can be converted to integers and back.
+ *)
+
+signature INTABLE = sig
+ type intable
+ val fromInt : Int.t -> intable
+ val fromLargeInt : LargeInt.t -> intable
+ val isoInt : (intable, Int.t) Iso.t
+ val isoLargeInt : (intable, LargeInt.t) Iso.t
+ val toInt : intable -> Int.t
+ val toLargeInt : intable -> LargeInt.t
+end
Property changes on: mltonlib/trunk/com/ssh/extended-basis/unstable/public/concept/intable.sig
___________________________________________________________________
Name: svn:eol-style
+ native
Added: mltonlib/trunk/com/ssh/extended-basis/unstable/public/concept/largeable.sig
===================================================================
--- mltonlib/trunk/com/ssh/extended-basis/unstable/public/concept/largeable.sig 2007-05-01 22:00:01 UTC (rev 5543)
+++ mltonlib/trunk/com/ssh/extended-basis/unstable/public/concept/largeable.sig 2007-05-06 07:32:40 UTC (rev 5544)
@@ -0,0 +1,20 @@
+(* Copyright (C) 2007 SSH Communications Security, Helsinki, Finland
+ *
+ * This code is released under the MLton license, a BSD-style license.
+ * See the LICENSE file or http://mlton.org/License for details.
+ *)
+
+(** == Largeable ==
+ *
+ * Corresponding to each group of largeable types (e.g. Int and Word
+ * types) there exists a "large" type (e.g. LargeInt, LargeWord) that can
+ * represent any value of the group of largeable types.
+ *)
+
+signature LARGEABLE = sig
+ type largeable
+ type largeable_large
+ val fromLarge : largeable_large -> largeable
+ val isoLarge : (largeable, largeable_large) Iso.t
+ val toLarge : largeable -> largeable_large
+end
Property changes on: mltonlib/trunk/com/ssh/extended-basis/unstable/public/concept/largeable.sig
___________________________________________________________________
Name: svn:eol-style
+ native
Added: mltonlib/trunk/com/ssh/extended-basis/unstable/public/concept/wordable.sig
===================================================================
--- mltonlib/trunk/com/ssh/extended-basis/unstable/public/concept/wordable.sig 2007-05-01 22:00:01 UTC (rev 5543)
+++ mltonlib/trunk/com/ssh/extended-basis/unstable/public/concept/wordable.sig 2007-05-06 07:32:40 UTC (rev 5544)
@@ -0,0 +1,20 @@
+(* Copyright (C) 2007 SSH Communications Security, Helsinki, Finland
+ *
+ * This code is released under the MLton license, a BSD-style license.
+ * See the LICENSE file or http://mlton.org/License for details.
+ *)
+
+(** == Wordable ==
+ *
+ * Wordables can be converted to words and back.
+ *)
+
+signature WORDABLE = sig
+ type wordable
+ val fromLargeWord : LargeWord.t -> wordable
+ val fromWord : Word.t -> wordable
+ val isoLargeWord : (wordable, LargeWord.t) Iso.t
+ val isoWord : (wordable, Word.t) Iso.t
+ val toLargeWord : wordable -> LargeWord.t
+ val toWord : wordable -> Word.t
+end
Property changes on: mltonlib/trunk/com/ssh/extended-basis/unstable/public/concept/wordable.sig
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: mltonlib/trunk/com/ssh/extended-basis/unstable/public/export/common.sml
===================================================================
--- mltonlib/trunk/com/ssh/extended-basis/unstable/public/export/common.sml 2007-05-01 22:00:01 UTC (rev 5543)
+++ mltonlib/trunk/com/ssh/extended-basis/unstable/public/export/common.sml 2007-05-06 07:32:40 UTC (rev 5544)
@@ -18,6 +18,10 @@
signature EQUALITY = EQUALITY
signature EQUALITY_CORE = EQUALITY_CORE
signature FLAGS = FLAGS
+signature FORMATTABLE = FORMATTABLE
+signature FORMATTABLE_and_SCANNABLE = FORMATTABLE_and_SCANNABLE
+signature FORMATTABLE_and_SCANNABLE_FROM_FORMAT =
+ FORMATTABLE_and_SCANNABLE_FROM_FORMAT
signature FUNC = FUNC
signature MAYBE_BOUNDED = MAYBE_BOUNDED
signature MAYBE_BOUNDED_CORE = MAYBE_BOUNDED_CORE
@@ -40,6 +44,7 @@
signature SIGNED = SIGNED
signature STRINGABLE = STRINGABLE
signature STRINGABLE_CORE = STRINGABLE_CORE
+signature WORDABLE = WORDABLE
(** === Module Signatures === *)
Modified: mltonlib/trunk/com/ssh/extended-basis/unstable/public/numeric/integer.sig
===================================================================
--- mltonlib/trunk/com/ssh/extended-basis/unstable/public/numeric/integer.sig 2007-05-01 22:00:01 UTC (rev 5543)
+++ mltonlib/trunk/com/ssh/extended-basis/unstable/public/numeric/integer.sig 2007-05-06 07:32:40 UTC (rev 5544)
@@ -1,4 +1,4 @@
-(* Copyright (C) 2006 SSH Communications Security, Helsinki, Finland
+(* Copyright (C) 2006-2007 SSH Communications Security, Helsinki, Finland
*
* This code is released under the MLton license, a BSD-style license.
* See the LICENSE file or http://mlton.org/License for details.
@@ -6,45 +6,32 @@
(** Extended {INTEGER} signature. *)
signature INTEGER = sig
- include BASIS_INTEGER
+ eqtype int
- type t = int
+ type t
(** Convenience alias. *)
- (** == Bounds == *)
+ (** == Misc == *)
- val bounds : t Sq.t Option.t
- (**
- * Pair of the minimal and maximal integers, respectively,
- * representable by {int}. If {minInt = NONE} and {maxInt = NONE},
- * this is also {NONE}. Otherwise this is {SOME (valOf minInt, valOf
- * maxInt)}.
- *)
+ val precision : Int.t Option.t
- (** == Embeddings == *)
+ val minInt : t Option.t
+ val maxInt : t Option.t
- val embString : (t, String.t) Emb.t
- (**
- * An embedding of integers into strings. It is always equivalent to
- * {(toString, fromString)}.
- *)
+ (** == Numeric == *)
- (** == Isomorphisms == *)
+ val + : t BinOp.t
+ val - : t BinOp.t
+ val * : t BinOp.t
- val isoInt : (t, Int.t) Iso.t
- (**
- * An isomorphism between integers of type {int} and the default
- * integer type. It is always equivalent to {(toInt, fromInt)}. Note
- * that one of the injection and projection parts may be partial.
- *)
+ val div : t BinOp.t
+ val mod : t BinOp.t
- val isoLarge : (t, LargeInt.t) Iso.t
- (**
- * An isomorphism between integers of type {int} and integers of type
- * {LargeInt.int}. It is always equivalent to {(toLarge, fromLarge)}.
- * Note that the projection part may be partial.
- *)
+ val quot : t BinOp.t
+ val rem : t BinOp.t
+ val ~ : t UnOp.t
+
(** == Predicates == *)
val isEven : t UnPr.t
@@ -61,4 +48,18 @@
val isZero : t UnPr.t
(** Returns true if the given integer is {0}. *)
+
+ (** == Concepts == *)
+
+ include FORMATTABLE_and_SCANNABLE_FROM_FORMAT
+ where type formattable_format = BasisStringCvt.radix
+ include INTABLE
+ include LARGEABLE where type largeable_large = LargeInt.t
+ include MAYBE_BOUNDED
+ include ORDERED
+ include SIGNED
+ include STRINGABLE
+
+ sharing type t = int = bounded = formattable = intable = largeable = ordered
+ = signed = stringable
end
More information about the MLton-commit
mailing list