You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 1307 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-1-a7-62-147-18-231.dial.proxad.net (62.147.18.231)
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 of
string * ([ 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 que
je 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:
Original bug ID: 1307
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-1-a7-62-147-18-231.dial.proxad.net (62.147.18.231)
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: