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: 7510 Reporter: LucFreget Assigned to:@Octachron Status: resolved (set by @Octachron on 2017-03-25T17:45:13Z) Resolution: not a bug Priority: normal Severity: trivial Platform: Mac OS: MacOS OS Version: Sierra 10.12.3 Version: 4.04.0 Category: misc
Bug description
Dans une fonction (en l'occurrence, une fonction récursive), l'expression [h1]@L2@[h2] n'est pas évaluée de la même façon que (xxx h1 h2 l2) quand xxx est définie comme suit:
begin print_list l1; print_string " "; print_list l2; print_string "\n";
match l1 with | [] -> l2 | [h] -> [h]@L2 | h1::h2::t -> fusion t (xxx h1 h2 l2); end;;
fusion lb la;;
1234 0000
34 100002
31000024
: int list = [3; 1; 0; 0; 0; 0; 2; 4]
JUSQU'ICI, TOUT VA BIEN
let rec fusion2 l1 l2 =
begin print_list l1; print_string " "; print_list l2; print_string "\n";
match l1 with | [] -> l2 | [h] -> [h]@L2 | h1::h2::t -> fusion2 t [h1]@L2@[h2]; end;;
fusion2 lb la;;
1234 0000
34 1
314
: int list = [3; 1; 4; 0; 0; 0; 0; 2]
La valeur retournée par la fonction fusion2 est différente de celle retournée par fusion, alors que la seule différence entre les deux fonctions est le remplacement de (xxx h1 h2 l2) par [h1]@L2@[h2].
Lorsque fusion2 est appelée récursivement, son deuxième argument vaut [1], quand on s'attend à [1; 0; 0; 0; 0; 2].
Additional information
Autre bizarrerie: dans l'exemple suivant, une arobase a été oubliée dans [h1]@L2[h2].
let rec fusion l1 l2 =
begin print_list l1; print_string " "; print_list l2; print_string "\n";
match l1 with | [] -> l2 | [h] -> [h]@L2 | h1::h2::t -> fusion t [h1]@L2[h2]; end;;
Warning 10: this expression should have type unit.
Warning 10: this expression should have type unit.
Error: This expression has type int list
This is not a function; it cannot be applied.
fusion lb la;;
1234 0000
34 100002
31000024
: int list = [3; 1; 0; 0; 0; 0; 2; 4]
The text was updated successfully, but these errors were encountered:
There is no issue within the code here: function application has a higher precedence than the concatenation operator (@). See http://ocaml.org/learn/ for more information.
Consequently,
fusion2 t [h1]@l2@[h2] = (fusion2 t [h1]) @l2@[h2]
<> fusion2 t ([h1]@L2@[h2]) = fusion2 t (xxx h1 h2 l2)
Il n'y aucun problème avec le code ici: l'application d'une fonction a simplement une plus grande priorité que l'opérateur de concaténation. Une explication plus approfondie du language OCaml est disponible sur http://ocaml.org/learn/.
Original bug ID: 7510
Reporter: LucFreget
Assigned to: @Octachron
Status: resolved (set by @Octachron on 2017-03-25T17:45:13Z)
Resolution: not a bug
Priority: normal
Severity: trivial
Platform: Mac
OS: MacOS
OS Version: Sierra 10.12.3
Version: 4.04.0
Category: misc
Bug description
Dans une fonction (en l'occurrence, une fonction récursive), l'expression [h1]@L2@[h2] n'est pas évaluée de la même façon que (xxx h1 h2 l2) quand xxx est définie comme suit:
let xxx a b l = [a]@l@[b];;
Steps to reproduce
#let la = [0; 0; 0; 0];;
#let lb = [1; 2; 3; 4];;
#let print_list l = List.map (fun item -> print_int item) l;;
#print_list la;;
0000
#print_list lb;;
1234
let xxx a b l = [a]@l@[b];;
let rec fusion l1 l2 =
begin print_list l1; print_string " "; print_list l2; print_string "\n";
match l1 with | [] -> l2 | [h] -> [h]@L2 | h1::h2::t -> fusion t (xxx h1 h2 l2); end;;
fusion lb la;;
1234 0000
34 100002
31000024
JUSQU'ICI, TOUT VA BIEN
let rec fusion2 l1 l2 =
begin print_list l1; print_string " "; print_list l2; print_string "\n";
match l1 with | [] -> l2 | [h] -> [h]@L2 | h1::h2::t -> fusion2 t [h1]@L2@[h2]; end;;
fusion2 lb la;;
1234 0000
34 1
314
La valeur retournée par la fonction fusion2 est différente de celle retournée par fusion, alors que la seule différence entre les deux fonctions est le remplacement de (xxx h1 h2 l2) par [h1]@L2@[h2].
Lorsque fusion2 est appelée récursivement, son deuxième argument vaut [1], quand on s'attend à [1; 0; 0; 0; 0; 2].
Additional information
Autre bizarrerie: dans l'exemple suivant, une arobase a été oubliée dans [h1]@L2[h2].
let rec fusion l1 l2 =
begin print_list l1; print_string " "; print_list l2; print_string "\n";
match l1 with | [] -> l2 | [h] -> [h]@L2 | h1::h2::t -> fusion t [h1]@L2[h2]; end;;
Warning 10: this expression should have type unit.
Warning 10: this expression should have type unit.
Error: This expression has type int list
This is not a function; it cannot be applied.
fusion lb la;;
1234 0000
34 100002
31000024
The text was updated successfully, but these errors were encountered: