Thanks for all the replies. The suggestion of @thierry-martinez works for `bind`

, but it breaks when I extend it with a `fail`

operator (which might be related to the call/cc remark by @xavierleroy):

```
module Cont = struct
type 'b fcont = unit -> 'b
type ('a,'b) cont = 'a -> 'b fcont -> 'b
type 'a t = {cont: 'b. (('a,'b) cont -> 'b fcont -> 'b)}
let ret (x: 'a) = {cont= fun k fcont -> k x fcont}
let bind (x: 'a t) (f: 'a -> 'b t) : 'b t =
{cont = fun k fcont -> x.cont (fun v fcont' -> (f v).cont k fcont') fcont}
let fail () = fun k fcont -> fcont ()
let rec branch l = {cont = fun k fcont ->
match l with
| [] -> fcont ()
| b :: bs -> (b ()).cont k (fun () -> branch bs k fcont) }
end
```

I get an error that my type is not general enough for the `fun`

```
Error: This field value has type ('c, 'd) cont -> 'd fcont -> 'd
which is less general than 'b. ('a, 'b) cont -> 'b fcont -> 'b
```

What Iâ€™m trying to write for this `branch`

function is to take a bunch of frozen computations, run them in order until one fail (then try the next one) or until the program terminates.

I tried splitting the recursive function to make it generic enough:

```
let rec gen_branch : 'b. (unit -> 'a t) list -> ('a,'b) cont -> 'b fcont -> 'b =
fun l k fcont ->
match l with
| [] -> fcont ()
| b :: bs -> (b ()).cont k (fun () -> gen_branch bs k fcont)
let branch l = {cont = gen_branch l}
```

but I get the same error (at the `gen_branch l`

call).

For the moment Iâ€™m using an approach similar to what @Chet_Murthy suggests, using a reference instead of an exception. Iâ€™m still curious to see if I can get enough polymorphism to succeed. Iâ€™m going to have a look at the papers Xavier suggests.

Finally, to reply to @ivg, the issue is that my monad need to conform to the type `'a t`

, i.e., I cannot mention the return type there. I agree the return type should be the same all the time for each instance of `run`

.