caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] writing a not too simple parametrized class interface
@ 2011-01-14 17:46 Philippe Strauss
  2011-01-15  0:53 ` Jeremy Yallop
  2011-01-15  1:00 ` Jacques Garrigue
  0 siblings, 2 replies; 3+ messages in thread
From: Philippe Strauss @ 2011-01-14 17:46 UTC (permalink / raw)
  To: caml-list

Hello ocaml users,

I'm in a fight with hindley-milner when writing a .mli for a set of classes which implement a pipeline pattern, for processing either float array or Complex.t array, caching the result in each pipeline element.

each element type (class) inherit from node_virt_t, which use parametrized type for circumventing around the lack of "c++" like method overloading, for having the ability to use either float array or Complex.t array as input/output data type.

the whole things works perfectly, but the .mli seems not easy to write.
uncomment class node_spectrum_t or class node_mag_t and you'll get:

File "nodes.mli", line 68, characters 30-45:
Error: The type parameter Complex.t array
       does not meet its constraint: it should be float array

which I don't understand.

thanks for any advice.

--8<-- nodes.mli :

type node_parameters_t = Spectrum | Mag | Magn | Smooth | Fade | Eqmp | Power | Trim

class type parameters_t =
    object
        val mutable len : int
        val mutable hlen : int
        val mutable sf : int
        val mutable chan : int
        val mutable f_half : float array
        val mutable f_log : float array
        val mutable fls : float
        val mutable fln : float
        val mutable fhn : float
        val mutable nth : float
        val mutable fll : float
        val mutable flh : float
        val mutable fhl : float
        val mutable fhh : float
        val mutable th_before : float
        val mutable th_after : float
        method set_len_sf : int -> int -> unit
        method get_len : int
        method get_hlen : int
        method get_sf : int
        method get_f_half : float array
        method get_f_log : float array
        method get_chan : int
        method set_chan : int -> unit
        method get_fln : float
        method set_fln : float -> unit
        method get_fhn : float
        method set_fhn : float -> unit
        method get_fls : float
        method set_fls : float -> unit
        method get_nth : float
        method set_nth : float -> unit
        method get_fade_freq : float * float * float * float
        method set_fade_freqs : float * float * float * float -> unit
        method get_th_before : float
        method set_th_before : float -> unit
        method get_th_after : float
        method set_th_after : float -> unit
        method get_parh : node_parameters_t -> string
end

class node_head_t : float array array ->
    object
        val impulses : float array array
        method get : int -> int * int * float array
end

class virtual ['b, 'c] node_virt_t : ('a, 'b) node_virt_t -> parameters_t -> int -> int ->
    object
        val previous : ('a, 'b) node_virt_t
        val parms : parameters_t
        val hres : (int * int * string, 'c) Hashtbl.t
        val mutable id : int array
        method get_id : int -> int
        method private inc_id : int -> unit
        method virtual ptyp : unit -> node_parameters_t
        method virtual process : 'b -> 'c
        method private pstore : int -> int * int * 'c
        method get : int -> int * int * 'c
end

(* class node_spectrum_t : node_head_t -> parameters_t -> int -> int ->
    object
        inherit [float array, Complex.t array] node_virt_t
        method ptyp : unit -> node_parameters_t
        method process : float array -> Complex.t array
end *)

(* class node_mag_t : (Complex.t array, float array) node_virt_t -> parameters_t -> int -> int ->
    object
        inherit [Complex.t array, float array] node_virt_t
        method ptyp : unit -> node_parameters_t
        method process :  Complex.t array -> float array
end *)

(* class node_magnormalize_t : (float array, float array) node_virt_t -> parameters_t -> int -> int ->
    object
        inherit [float array, float array] node_virt_t
        method ptyp : unit -> node_parameters_t
        method process :  float array -> float array
end *)

(* class node_smooth_t : (float array, float array) node_virt_t -> parameters_t -> int -> int ->
    object
        inherit [float array, float array] node_virt_t
        method ptyp : unit -> node_parameters_t
        method process :  float array -> float array
end *)

(* class node_fade_t : (float array, float array) node_virt_t -> parameters_t -> int -> int ->
    object
        inherit [float array, float array] node_virt_t
        method ptyp : unit -> node_parameters_t
        method process :  float array -> float array
end *)

(* class node_eqminphase_t : (float array, float array) node_virt_t -> parameters_t -> int -> int ->
    object
        inherit [float array, float array] node_virt_t
        method ptyp : unit -> node_parameters_t
        method process :  float array -> float array
end *)

(* class node_power_t : (float array, float array) node_virt_t -> parameters_t -> int -> int ->
    object
        inherit [float array, float array] node_virt_t
        method ptyp : unit -> node_parameters_t
        method process :  float array -> float array
end *)

(* class node_trim_t : (float array, float array) node_virt_t -> (float array, float array) node_virt_t -> parameters_t ->
    object
        val nd_eqmp : (float array, float array) node_virt_t
        val nd_powm : (float array, float array) node_virt_t
        val parms : parameters_t
        method ptyp : unit -> node_parameters_t
        method make_coeffs : unit
end *)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-01-15  1:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-14 17:46 [Caml-list] writing a not too simple parametrized class interface Philippe Strauss
2011-01-15  0:53 ` Jeremy Yallop
2011-01-15  1:00 ` Jacques Garrigue

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).