On 6 avril 2014 21:15:25 UTC+02:00, Edgar Friendly <notifications@github.com> wrote:
>> @@ -294,19 +327,21 @@ module Concrete = struct
>>        | C (_, _, m, t) -> aux (n + 1 + cardinal m) t
>>      in aux 0 !l
>>  
>> -  let enum t =
>> -    let rec make l =
>> -      let l = ref l in
>> -      let clone() = make !l in
>> -      BatEnum.make ~next:(enum_next l) ~count:(enum_count l) ~clone
>> -    in make (cons_iter t E)
>> +  let rec enum_of_iter l =
>> +    let l = ref l in
>> +    let clone() = enum_of_iter !l in
>> +    BatEnum.make ~next:(enum_next l) ~count:(enum_count l) ~clone
>> +
>
>I suspect this pattern might be usefully brought into `Enum` as another
>constructor function (or possibly deeper, although this may
>require/allow a rewrite) so that the implicit mutable state in an Enum
>can be made explicit for easier management. (less bugs)

This is an interesting insight. I wrote some iterators with an explicit state (e.g. Cartesian product) to make counting and cloning easier, so I believe it's a good way of building Enums.

That makes me think that by making the state explicit, I see 'a enum as a function of (state, unit) -> 'a. Generalizing, we get automata, ie functions (state, 'a) -> 'b, that can be composed together and cloned (by cloning the state). Could be an interesting abstraction?