New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typage de variants polymorphes pas assez restrictive #3514
Comments
Comment author: administrator
[..]
A
Il faut regarder le type de print_decls val print_decls : Note la recursion en 'b: le type de l'argument de Rien que de tres normal, mais je comprends ta confusion.
Par definition un type non-ferme' n'est pas restrictif. fun x -> (x : T.modtype :> [> T.modtype]) Jacques |
Original bug ID: 1306
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)
Bug description
Full_Name: Boris Yakobowski
Version: 3.04+15
OS: Linux
Submission from: lyon-4-a7-62-147-48-55.dial.proxad.net (62.147.48.55)
Bonjour à tous.
Je pense qu'il y a un bug dans la propagation des informations de typage dans
les variants polymorphes.
Lorsqu'on compile le code suivant
module T = struct
type signature_item = [
|
Module of string * modtype] and modtype = [ |
Sig of signature_item list| `Functor of (string * modtype) * modtype]
end
let rec print_decl = function
|
Module (p, d) -> "module " ^ p ^ " : " ^ (print_modtype d) ^"\n" and print_modtype = function |
Sig s -> " sig " ^ (print_decls s) ^ "end"| `Functor ((param_name, param), result) -> "functor (" ^ param_name ^ ": " ^
(print_modtype param) ^ ") -> (" ^ (print_modtype result) ^ ")"
and print_decls l = List.fold_left (^) "" (List.map (fun d -> (print_decl d) ^
"\n") l)
let rec flatten_decl = function
|
Module (x,
Sig d) -> flatten_decls d|
Module (n,
Functor ((narg,Sig arg),
Sig res)) ->let arg' = flatten_decls arg in
let res' = flatten_decls res in
(* let m = "(functor (F : sig\n" ^ (print_decls arg') ^ " end) -> (struct
(* Converter ) end))" in ( Faulty *) *)
[
Module (n,
Functor ((narg,Sig arg'),
Sig res'))]and flatten_decls d = List.flatten (List.map (fun x -> flatten_decl x) d)
on obtient comme type pour flatten_decl
val flatten_decl :
([
Module of 'b * [<
Functor of ('c * [Sig of 'a list]) * [
Sig of 'a list]|
Sig of 'a list]] as 'a) -> ([>
Module of 'b * [>Functor of ('c * [>
Sig of 'd]) * [> `Sig of 'd]]]list as 'd)
qui me parait correct.
Par contre, si on décommente la ligne marquée FAULTY, on obtient
val flatten_decl :
([
Module of string * [<
Functor of (string * [Sig of 'a list]) * [
Sig of 'a list]|
Sig of 'a list]] as 'a) -> ([
Module ofstring * ([
Functor of (string * 'c) * 'c |
Sig of 'b] as 'c)]list as 'b)
Dans le type de retour de la fonction,
Module pourrait prendre comme paramètre des
Sig, ce qui est faux (et qui n'apparait pas dans le premier type). Ce queje ne comprends pas c'est pourquoi le typeur rajoute des variants dans le type,
alors que la valeur retournée par la fonction ne change pas (puisque print_decl
n'altère pas son argument).
Avec du code moins nettoyé, j'obtiens comme type
val flatten_decl :
string ->
(string * string) list ->
string ->
([<
AbstractType of string * int list |
ManifestType of string * T.type_expr * int list|
Module of string * ([<
Functor of (string * 'b) * 'b|
Name of string |
Sig of 'a list] as 'b) &string *
([<
Functor of (string * 'c) * 'c |
Name of string|
Sig of 'a list] as 'c) & string * [<
Functor of (string * [Sig of 'a list]) * [
Sig of 'a list]|
Sig of 'a list] |
Val of string * T.type_expr] as 'a) ->([
AbstractType of string * int list |
ManifestType of string * T.type_expr * int list|
Module of string * ([<
Functor of (string * 'e) * 'e |Name of string |
Sig of 'd>
Functor
Sig] as 'e)| `Val of string * T.type_expr] list as 'd) *
(string * string) list * (string * string)
qui n'est pas non plus assez restrictif, mais qui n'est pas fermé.
Quoi qu'il en soit, merci à Jacques pour les variants polymorphes, même si ce
problème est génant j'aurai quand même économisé beaucoup de réécriture de code
sur d'autres parties.
The text was updated successfully, but these errors were encountered: