[MLton-commit] r5382
Vesa Karvonen
vesak at mlton.org
Fri Mar 2 01:40:44 PST 2007
Removed the MONAD and CFUNC signatures with the extra type parameter.
----------------------------------------------------------------------
U mltonlib/trunk/com/ssh/extended-basis/unstable/detail/mk-monad.fun
U mltonlib/trunk/com/ssh/extended-basis/unstable/public/concept/func.sig
U mltonlib/trunk/com/ssh/extended-basis/unstable/public/concept/monad.sig
U mltonlib/trunk/com/ssh/extended-basis/unstable/public/export/common.sml
----------------------------------------------------------------------
Modified: mltonlib/trunk/com/ssh/extended-basis/unstable/detail/mk-monad.fun
===================================================================
--- mltonlib/trunk/com/ssh/extended-basis/unstable/detail/mk-monad.fun 2007-03-02 08:58:11 UTC (rev 5381)
+++ mltonlib/trunk/com/ssh/extended-basis/unstable/detail/mk-monad.fun 2007-03-02 09:40:36 UTC (rev 5382)
@@ -4,12 +4,12 @@
* See the LICENSE file or http://mlton.org/License for details.
*)
-functor MkMonad' (MonadCore : MONAD_CORE') : MONAD' = struct
+functor MkMonad (MonadCore : MONAD_CORE) : MONAD = struct
infix >> >>& >>* >>= >>@
open MonadCore
- type ('a, 'x1) func = ('a, 'x1) monad
+ type 'a func = 'a monad
fun map f aM = aM >>= return o f
- type ('a, 'x1) monad_ex = ('a, 'x1) monad
+ type 'a monad_ex = 'a monad
fun aM >>* bM = aM >>= (fn a => bM >>= Fn.<\ (a, return))
fun fM >>@ aM = map Fn.\> (fM >>* aM)
fun aM >>& bM = map Product.& (aM >>* bM)
@@ -18,24 +18,9 @@
| seq (xM::xMs) = map op :: (xM >>* seq xMs)
end
-functor MkMonad (MonadCore : MONAD_CORE) : MONAD = struct
- structure Monad = MkMonad' (open MonadCore type ('a, 'b) monad = 'a monad)
- open Monad MonadCore
- type 'a func = 'a monad
- type 'a monad_ex = 'a monad
-end
-
-functor MkMonadP' (MonadPCore : MONADP_CORE') : MONADP' = struct
- structure Monad = MkMonad' (MonadPCore)
+functor MkMonadP (MonadPCore : MONADP_CORE) : MONADP = struct
+ structure Monad = MkMonad (MonadPCore)
open Monad MonadPCore
- type ('a, 'x) monadp_ex = ('a, 'x) monad
+ type 'a monadp_ex = 'a monad
fun sum [] = zero | sum [x] = x | sum (x::xs) = plus (x, sum xs)
end
-
-functor MkMonadP (MonadPCore : MONADP_CORE) : MONADP = struct
- structure MonadP = MkMonadP' (open MonadPCore type ('a, 'b) monad = 'a monad)
- open MonadP MonadPCore
- type 'a func = 'a monad
- type 'a monad_ex = 'a monad
- type 'a monadp_ex = 'a monad
-end
Modified: mltonlib/trunk/com/ssh/extended-basis/unstable/public/concept/func.sig
===================================================================
--- mltonlib/trunk/com/ssh/extended-basis/unstable/public/concept/func.sig 2007-03-02 08:58:11 UTC (rev 5381)
+++ mltonlib/trunk/com/ssh/extended-basis/unstable/public/concept/func.sig 2007-03-02 09:40:36 UTC (rev 5382)
@@ -4,24 +4,28 @@
* See the LICENSE file or http://mlton.org/License for details.
*)
+(** == Functor or Covariant Functor ==
+ *
+ * The concept of a functor comes from category theory. Here a functor
+ * consists of a type constructor {func} and a function {map}:
+ *
+ *> type 'a func
+ *> val map : ('a -> 'b) -> 'a func -> 'b func
+ *
+ * Furthermore, the {map} function must obey two laws:
+ *
+ *> 1. map id == id
+ *> 2. map (f o g) == map f o map g
+ *)
+
signature FUNC = sig
type 'a func
val map : ('a -> 'b) -> 'a func -> 'b func
end
+(** == Contravariant Functor == *)
+
signature CFUNC = sig
type 'a func
val map : ('b -> 'a) -> 'a func -> 'b func
end
-
-(************************************************************************)
-
-signature FUNC' = sig
- type ('a, 'x1) func
- val map : ('a -> 'b) -> ('a, 'x1) func -> ('b, 'x1) func
-end
-
-signature CFUNC' = sig
- type ('a, 'x1) func
- val map : ('b -> 'a) -> ('a, 'x1) func -> ('b, 'x1) func
-end
Modified: mltonlib/trunk/com/ssh/extended-basis/unstable/public/concept/monad.sig
===================================================================
--- mltonlib/trunk/com/ssh/extended-basis/unstable/public/concept/monad.sig 2007-03-02 08:58:11 UTC (rev 5381)
+++ mltonlib/trunk/com/ssh/extended-basis/unstable/public/concept/monad.sig 2007-03-02 09:40:36 UTC (rev 5382)
@@ -4,7 +4,26 @@
* See the LICENSE file or http://mlton.org/License for details.
*)
-(** == Monad == *)
+(** == Monad ==
+ *
+ * The concept of a monad comes from category theory. Here a monad
+ * consists of a type constructor {monad} and two functions {return} and
+ * {>>=} (pronounced "bind"):
+ *
+ *> type 'a monad
+ *> val return : 'a -> 'a monad
+ *> val >>= : 'a monad * ('a -> 'b monad) -> 'b monad
+ *
+ * Furthermore, the {return} and {>>=} functions must obey three laws:
+ *
+ *> 1. return x >>= f == f x
+ *> 2. m >>= return == m
+ *> 3. (m >>= f) >>= g == m >>= (fn x => f x >>= g)
+ *
+ * The first two laws basically say that {return} is both a left and
+ * right-identity with respect to {>>=}. The third law basically says
+ * that {>>=} is associative.
+ *)
signature MONAD_CORE = sig
type 'a monad
@@ -45,46 +64,3 @@
include MONAD_EX where type 'a monad_ex = 'a monad
include MONADP_EX where type 'a monadp_ex = 'a monad
end
-
-(************************************************************************)
-
-(* XXX Should the following be removed? *)
-
-signature MONAD_CORE' = sig
- type ('a, 'x) monad
- val return : 'a -> ('a, 'x) monad
- val >>= : ('a, 'x) monad * ('a -> ('b, 'x) monad) -> ('b, 'x) monad
-end
-
-signature MONAD_EX' = sig
- type ('a, 'x) monad_ex
- include FUNC' where type ('a, 'x) func = ('a, 'x) monad_ex
- val >> : ('a, 'x) monad_ex * ('b, 'x) monad_ex -> ('b, 'x) monad_ex
- val >>* : ('a, 'x) monad_ex * ('b, 'x) monad_ex -> ('a * 'b, 'x) monad_ex
- val >>& : ('a, 'x) monad_ex * ('b, 'x) monad_ex
- -> (('a, 'b) Product.t, 'x) monad_ex
- val >>@ : ('a -> 'b, 'x) monad_ex * ('a, 'x) monad_ex -> ('b, 'x) monad_ex
- val seq : ('a, 'x) monad_ex List.t -> ('a List.t, 'x) monad_ex
-end
-
-signature MONAD' = sig
- include MONAD_CORE'
- include MONAD_EX' where type ('a, 'x) monad_ex = ('a, 'x) monad
-end
-
-signature MONADP_CORE' = sig
- include MONAD_CORE'
- val zero : ('a, 'x) monad
- val plus : ('a, 'x) monad BinOp.t
-end
-
-signature MONADP_EX' = sig
- type ('a, 'x) monadp_ex
- val sum : ('a, 'x) monadp_ex List.t -> ('a, 'x) monadp_ex
-end
-
-signature MONADP' = sig
- include MONADP_CORE'
- include MONAD_EX' where type ('a, 'x) monad_ex = ('a, 'x) monad
- include MONADP_EX' where type ('a, 'x) monadp_ex = ('a, 'x) monad
-end
Modified: mltonlib/trunk/com/ssh/extended-basis/unstable/public/export/common.sml
===================================================================
--- mltonlib/trunk/com/ssh/extended-basis/unstable/public/export/common.sml 2007-03-02 08:58:11 UTC (rev 5381)
+++ mltonlib/trunk/com/ssh/extended-basis/unstable/public/export/common.sml 2007-03-02 09:40:36 UTC (rev 5382)
@@ -10,19 +10,13 @@
signature BITWISE = BITWISE
signature CFUNC = CFUNC
-signature CFUNC' = CFUNC'
signature CSTRINGABLE = CSTRINGABLE
signature FLAGS = FLAGS
signature FUNC = FUNC
-signature FUNC' = FUNC'
signature MONAD = MONAD
-signature MONAD' = MONAD'
signature MONADP = MONADP
-signature MONADP' = MONADP'
signature MONADP_CORE = MONADP_CORE
-signature MONADP_CORE' = MONADP_CORE'
signature MONAD_CORE = MONAD_CORE
-signature MONAD_CORE' = MONAD_CORE'
signature ORDERED = ORDERED
signature SIGNED = SIGNED
signature STRINGABLE = STRINGABLE
@@ -147,7 +141,5 @@
(** === Functors === *)
functor MkMonad (Arg : MONAD_CORE) : MONAD = MkMonad (Arg)
-functor MkMonad' (Arg : MONAD_CORE') : MONAD' = MkMonad' (Arg)
functor MkMonadP (Arg : MONADP_CORE) : MONADP = MkMonadP (Arg)
-functor MkMonadP' (Arg : MONADP_CORE') : MONADP' = MkMonadP' (Arg)
functor MkWordFlags (Arg : WORD) : FLAGS = MkWordFlags (Arg)
More information about the MLton-commit
mailing list