[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Jacques Carette <carette@m...> |
| Subject: | Re: [Caml-list] Re: (continuation monad) type problem... |
It seems that a small modification to the definition of ContT can
restore polymophism:
module ContT (M : Monad) = struct
type res = unit
type ('a,'b) k = Cont of (('a -> 'b m) -> 'b m)
and 'a m = (res * ('a,res) k M.m) M.m
let return a = Cont (fun c -> c a)
let bind m k = Cont (fun c ->
let (Cont m') = m in m' (fun a ->
let (Cont ka') = k a in ka' c))
end;;
The main change is that to have 2 type parameters in your
continuation. Also note that while 'a m is defined in terms of res (ie
unit) for its second parameter, we know this doesn't matter (since
continuations never really "return"), and thus ocaml is able to infer a
polymorphic type for bind:
val bind : ('a, 'b) k -> ('a -> ('c, 'b) k) -> ('c, 'b) k
Jacques