From: Philippe Strauss <philou@philou.ch>
To: caml-list@inria.fr
Subject: [Caml-list] writing a not too simple parametrized class interface
Date: Fri, 14 Jan 2011 18:46:43 +0100 [thread overview]
Message-ID: <C7AAD554-4DA5-4811-8AAA-84E14E46C31D@philou.ch> (raw)
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 *)
next reply other threads:[~2011-01-14 17:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-14 17:46 Philippe Strauss [this message]
2011-01-15 0:53 ` Jeremy Yallop
2011-01-15 1:00 ` Jacques Garrigue
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=C7AAD554-4DA5-4811-8AAA-84E14E46C31D@philou.ch \
--to=philou@philou.ch \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox