Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] View of /tests/trunk/bugs/tests.obsolete/bug1322.1.sml
ViewVC logotype

View of /tests/trunk/bugs/tests.obsolete/bug1322.1.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2460 - (download) (annotate)
Sat Apr 28 20:18:10 2007 UTC (12 years, 2 months ago) by gkuan
File size: 666 byte(s)
(* bug1322.1.sml *)

signature MONAD = 
sig
  type 'a T
  val unit : 'a -> 'a T
  val bind : 'a T -> ('a -> 'b T) -> 'b T
end;

structure IdMonad =
struct
  type 'a T = 'a
  fun unit x = x
  fun bind m f = f m
end;

functor StMonad(structure Monad : MONAD type State) =
struct
  structure M =
  struct
    type 'a T = State -> (State * 'a) Monad.T
    fun unit x = fn s => Monad.unit (s, x)
    fun bind m k = fn s0 => Monad.bind (m s0) (fn (s1, a) => k a s1)
  end
  fun update f = fn s => Monad.unit (f s, s)
(* Works if you remove this defn *)
  val read = update (fn s : State => s)
end;

structure StMonad = StMonad(structure Monad = IdMonad type State = int);

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0