Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Fieldslib interface #169

Closed
roshanjames opened this Issue Jan 30, 2014 · 3 comments

Comments

Projects
None yet
2 participants

There is some inconsistency between what Merlin understands for [with fields'] and what is generated:

module M = struct
  type t = {
    x : int;
    y : float ref;
  } with fields
end

This is the module type generated by merlin:

sig
  type t = { x : int; y : float ref; }
  val x : t -> int
  val y : t -> float ref
  module Fields :
    sig
      val x : (t, int) Field.t
      val y : (t, float ref) Field.t
      val fold :
        init:'a ->
        x:('a -> (t, int) Field.t -> 'b) ->
        y:('b -> (t, float ref) Field.t -> 'c) -> 'c
      val iter :
        x:((t, int) Field.t -> unit) ->
        y:((t, float ref) Field.t -> unit) -> unit
      val map :
        x:((t, int) Field.t -> int) ->
        y:((t, float ref) Field.t -> float ref) -> t
      val for_all :
        x:((t, int) Field.t -> bool) ->
        y:((t, float ref) Field.t -> bool) -> bool
      val exists :
        x:((t, int) Field.t -> bool) ->
        y:((t, float ref) Field.t -> bool) -> bool
    end
end

and this is what utop reports:

utop # type t = { x : int; y : float ref; } with fields;;
type t = { x : int; y : float ref; }                                                                             val y : t -> float ref = <fun>                                                                                   val x : t -> int = <fun>                                                                                         
module Fields :
  sig
    val names : string list
    val y : ([< `Read | `Set_and_create ], t, float ref) Field.t_with_perm
    val x : ([< `Read | `Set_and_create ], t, int) Field.t_with_perm
    val make_creator :
      x:(([< `Read | `Set_and_create ], t, int) Field.t_with_perm -> 'a -> ('b -> int) * 'c) ->
      y:(([< `Read | `Set_and_create ], t, float ref) Field.t_with_perm -> 'c -> ('b -> float ref) * 'd) ->
      'a -> ('b -> t) * 'd
    val create : x:int -> y:float ref -> t
    val map :
      x:(([< `Read | `Set_and_create ], t, int) Field.t_with_perm -> int) ->
      y:(([< `Read | `Set_and_create ], t, float ref) Field.t_with_perm -> float ref) -> t
    val iter :
      x:(([< `Read | `Set_and_create ], t, int) Field.t_with_perm -> 'a) ->
      y:(([< `Read | `Set_and_create ], t, float ref) Field.t_with_perm -> 'b) -> 'b
    val fold :
      init:'a ->
      x:('a -> ([< `Read | `Set_and_create ], t, int) Field.t_with_perm -> 'b) ->
      y:('b -> ([< `Read | `Set_and_create ], t, float ref) Field.t_with_perm -> 'c) -> 'c
    val map_poly : ([< `Read | `Set_and_create ], t, 'a) Field.user -> 'a list
    val for_all :
      x:(([< `Read | `Set_and_create ], t, int) Field.t_with_perm -> bool) ->
      y:(([< `Read | `Set_and_create ], t, float ref) Field.t_with_perm -> bool) -> bool
    val exists :
      x:(([< `Read | `Set_and_create ], t, int) Field.t_with_perm -> bool) ->
      y:(([< `Read | `Set_and_create ], t, float ref) Field.t_with_perm -> bool) -> bool
    val to_list :
      x:(([< `Read | `Set_and_create ], t, int) Field.t_with_perm -> 'a) ->
      y:(([< `Read | `Set_and_create ], t, float ref) Field.t_with_perm -> 'a) -> 'a list
    module Direct :
      sig
        val iter :
          t ->
          x:(([< `Read | `Set_and_create ], t, int) Field.t_with_perm -> t -> int -> 'a) ->
          y:(([< `Read | `Set_and_create ], t, float ref) Field.t_with_perm -> t -> float ref -> 'b) -> 'b
        val fold :
          t ->
          init:'a ->
          x:('a -> ([< `Read | `Set_and_create ], t, int) Field.t_with_perm -> t -> int -> 'b) ->
          y:('b -> ([< `Read | `Set_and_create ], t, float ref) Field.t_with_perm -> t -> float ref -> 'c) -> 'c
      end
  end

@trefis trefis closed this in fbf669f Feb 7, 2014

Contributor

trefis commented Feb 7, 2014

Done!

The signature generated by merlin for the iter function is more constrained than what fieldslib generates (I forced the return type to be unit), if that causes you any trouble tell me and I'll change it.

Thanks!

On Feb 7, 2014, at 4:54 PM, Thomas Refis notifications@github.com wrote:

Btw: https://github.com/janestreet/fieldslib/blob/master/README.txt is not up to date.


Reply to this email directly or view it on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment