Knowledge

Value restriction

Source đź“ť

63: 475: 22: 260: 125: 470:{\displaystyle {\begin{aligned}{\mathtt {ref}}&:\forall \alpha .\alpha \to (\alpha \ {\mathtt {ref}})\\{\mathtt {!}}&:\forall \alpha .(\alpha \ {\mathtt {ref}})\to \alpha \\{\mathtt {:=}}&:\forall \alpha .(\alpha \ {\mathtt {ref}})\to \alpha \to {\mathtt {unit}}\end{aligned}}} 852: 1076: 774: 706: 265: 1133: 977: 920:
operator are not generalized. It is safe to generalize type variables of syntactic values because their evaluation cannot cause any side-effects such as writing to a reference.
918: 1166: 511: 559: 535: 888: 997: 890:-expressions and constructors applied to values. The function and operator applications are not considered values. In particular, applications of the 783: 1013: 711: 654: 1000: 35: 1178: 179: 161: 143: 106: 84: 49: 236: 193: 1079: 209: 1283: 1092: 934: 252: 201: 77: 71: 1329: 866:
Under the value restriction, the types of let bound expressions are only generalized if the expressions are
240: 213: 1261:
O'Toole (1990). "Type Abstraction Rules for Reference: A Comparison of Four Which Have Achieved Notoriety".
1291: 197: 88: 41: 565:. Given these, the following program unsoundly applies a function meant for integers to a Boolean value. 480: 223:). The value restriction prevents reference cells from holding values of different types and preserves 893: 1278: 1138: 1232: 486: 216: 540: 516: 1224: 1316:— Principles of Programming Languages, Geoffrey Smith, Florida International University 1264:
Xavier Leroy & Pierre Weis (1991). "Polymorphic type inference and assignment". POPL '91.
870:. In his paper, Wright considers the following to be syntactic values: constants, variables, 1274:
and Ramesh Viswanathan (1993). "Standard ML-NJ weak polymorphism and imperative constructs".
1271: 1216: 923:
The above example is rejected by the type checker under the value restriction as follows.
873: 1313: 982: 1323: 1236: 561:(assignment) updates a reference to contain a new value and returns a value of the 248: 244: 224: 1248: 1228: 562: 537:(dereference) takes a reference and reads the value in that reference, and 1220: 1204: 1304: 847:{\textstyle ({\mathtt {bool}}\to {\mathtt {bool}})\ {\mathtt {ref}}} 134:
provides insufficient context for those unfamiliar with the subject
1308: 1071:{\textstyle ({\mathtt {int}}\to {\mathtt {int}})\ {\mathtt {ref}}} 769:{\textstyle ({\mathtt {int}}\to {\mathtt {int}})\ {\mathtt {ref}}} 701:{\textstyle \forall \alpha .(\alpha \to \alpha )\ {\mathtt {ref}}} 118: 56: 15: 1267:
A. K. Wright (1992). "Typing references by effect inference".
1258:
M. Tofte (1990). "Type inference for polymorphic references".
513:
takes a value and creates a reference containing that value,
647:
The above program type checks using Hindley-Milner because
243:. But naively giving multiple types to references breaks 139: 1141: 1016: 1003:
in the typing context for the body of the let binding.
985: 937: 876: 786: 714: 657: 543: 519: 489: 1095: 896: 263: 1253:
Operational Semantics and Polymorphic Type Inference
1160: 1128:{\displaystyle {\mathtt {int}}\to {\mathtt {int}}} 1127: 1070: 991: 972:{\textstyle (\alpha \to \alpha )\ {\mathtt {ref}}} 971: 912: 882: 846: 768: 700: 553: 529: 505: 469: 239:, expressions can be given multiple types through 1010:is modified in the typing context to be of type 708:, which is then instantiated to be of the type 8: 1168:, and the type checker rejects the program. 50:Learn how and when to remove these messages 1006:When the assignment is typed, the type of 219:if they are syntactic values (also called 1143: 1142: 1140: 1113: 1112: 1097: 1096: 1094: 1056: 1055: 1037: 1036: 1021: 1020: 1015: 984: 957: 956: 936: 898: 897: 895: 875: 832: 831: 810: 809: 791: 790: 785: 754: 753: 735: 734: 719: 718: 713: 686: 685: 656: 545: 544: 542: 521: 520: 518: 491: 490: 488: 448: 447: 423: 422: 391: 390: 365: 364: 333: 332: 313: 312: 269: 268: 264: 262: 180:Learn how and when to remove this message 162:Learn how and when to remove this message 107:Learn how and when to remove this message 251:for references and related operators in 70:This article includes a list of general 1190: 1153: 1150: 1147: 1144: 1120: 1117: 1114: 1104: 1101: 1098: 1063: 1060: 1057: 1044: 1041: 1038: 1028: 1025: 1022: 964: 961: 958: 905: 902: 899: 839: 836: 833: 820: 817: 814: 811: 801: 798: 795: 792: 761: 758: 755: 742: 739: 736: 726: 723: 720: 693: 690: 687: 546: 522: 498: 495: 492: 458: 455: 452: 449: 430: 427: 424: 392: 372: 369: 366: 334: 320: 317: 314: 276: 273: 270: 144:providing more context for the reader 7: 1198: 1196: 1194: 1135:, but is applied to a value of type 1179:Hindley–Milner type inference 979:. This type is not generalized and 1314:Notes on SML97's Value Restriction 658: 404: 346: 288: 76:it lacks sufficient corresponding 14: 479:The operators have the following 204:programming language family, the 31:This article has multiple issues. 1292:"Relaxing the Value Restriction" 1205:"Simple imperative polymorphism" 1203:Wright, Andrew K. (1995-12-01). 854:ref when typing the dereference 231:A Counter Example to Type Safety 123: 61: 20: 913:{\displaystyle {\mathtt {ref}}} 39:or discuss these issues on the 1279:Simple imperative polymorphism 1109: 1049: 1033: 1017: 950: 944: 938: 825: 806: 787: 747: 731: 715: 679: 673: 667: 444: 438: 435: 413: 380: 377: 355: 325: 303: 300: 192:In programming languages with 1: 1284:LISP and Symbolic Computation 1209:LISP and Symbolic Computation 1161:{\textstyle {\mathtt {bool}}} 778:c := (fn x => x + 1) 506:{\textstyle {\mathtt {ref}}} 200:features, in particular the 776:when typing the assignment 554:{\textstyle {\mathtt {:=}}} 1346: 530:{\textstyle {\mathtt {!}}} 237:Hindley–Milner type system 1290:Jacques Garrigue (2004). 567: 1277:Andrew Wright (1995). " 241:parametric polymorphism 91:more precise citations. 1162: 1129: 1072: 993: 973: 914: 884: 848: 770: 702: 555: 531: 507: 471: 1163: 1130: 1073: 994: 974: 915: 885: 883:{\textstyle \lambda } 862:The Value Restriction 849: 771: 703: 556: 532: 508: 472: 1139: 1093: 1014: 992:{\textstyle \alpha } 983: 935: 894: 874: 784: 712: 655: 541: 517: 487: 261: 247:. The following are 196:type inference and 140:improve the article 1287:, p. 343–356. 1221:10.1007/BF01018828 1158: 1125: 1068: 989: 969: 931:is given the type 910: 880: 844: 766: 698: 651:is given the type 551: 527: 503: 467: 465: 1305:Value Restriction 1054: 955: 830: 752: 684: 421: 363: 311: 255:-like languages. 206:value restriction 190: 189: 182: 172: 171: 164: 117: 116: 109: 54: 1337: 1272:John C. Mitchell 1241: 1240: 1200: 1167: 1165: 1164: 1159: 1157: 1156: 1134: 1132: 1131: 1126: 1124: 1123: 1108: 1107: 1088: 1085:The dereference 1077: 1075: 1074: 1069: 1067: 1066: 1052: 1048: 1047: 1032: 1031: 1009: 998: 996: 995: 990: 978: 976: 975: 970: 968: 967: 953: 930: 919: 917: 916: 911: 909: 908: 889: 887: 886: 881: 868:syntactic values 857: 853: 851: 850: 845: 843: 842: 828: 824: 823: 805: 804: 779: 775: 773: 772: 767: 765: 764: 750: 746: 745: 730: 729: 707: 705: 704: 699: 697: 696: 682: 650: 643: 640: 637: 634: 631: 628: 625: 622: 619: 616: 613: 610: 607: 604: 601: 598: 595: 592: 589: 586: 583: 580: 577: 574: 571: 560: 558: 557: 552: 550: 549: 536: 534: 533: 528: 526: 525: 512: 510: 509: 504: 502: 501: 476: 474: 473: 468: 466: 462: 461: 434: 433: 419: 396: 395: 376: 375: 361: 338: 337: 324: 323: 309: 280: 279: 185: 178: 167: 160: 156: 153: 147: 127: 126: 119: 112: 105: 101: 98: 92: 87:this article by 78:inline citations 65: 64: 57: 46: 24: 23: 16: 1345: 1344: 1340: 1339: 1338: 1336: 1335: 1334: 1320: 1319: 1301: 1245: 1244: 1202: 1201: 1192: 1187: 1175: 1137: 1136: 1091: 1090: 1086: 1012: 1011: 1007: 981: 980: 933: 932: 928: 892: 891: 872: 871: 864: 855: 782: 781: 777: 710: 709: 653: 652: 648: 645: 644: 641: 638: 635: 632: 629: 626: 623: 620: 617: 614: 611: 608: 605: 602: 599: 596: 593: 590: 587: 584: 581: 578: 575: 572: 569: 539: 538: 515: 514: 485: 484: 464: 463: 397: 387: 386: 339: 329: 328: 281: 259: 258: 233: 214:polymorphically 186: 175: 174: 173: 168: 157: 151: 148: 137: 128: 124: 113: 102: 96: 93: 83:Please help to 82: 66: 62: 25: 21: 12: 11: 5: 1343: 1341: 1333: 1332: 1330:Type inference 1322: 1321: 1318: 1317: 1311: 1300: 1299:External links 1297: 1296: 1295: 1288: 1275: 1268: 1265: 1262: 1259: 1256: 1243: 1242: 1215:(4): 343–355. 1189: 1188: 1186: 1183: 1182: 1181: 1174: 1171: 1170: 1169: 1155: 1152: 1149: 1146: 1122: 1119: 1116: 1111: 1106: 1103: 1100: 1083: 1065: 1062: 1059: 1051: 1046: 1043: 1040: 1035: 1030: 1027: 1024: 1019: 1004: 988: 966: 963: 960: 952: 949: 946: 943: 940: 907: 904: 901: 879: 863: 860: 841: 838: 835: 827: 822: 819: 816: 813: 808: 803: 800: 797: 794: 789: 763: 760: 757: 749: 744: 741: 738: 733: 728: 725: 722: 717: 695: 692: 689: 681: 678: 675: 672: 669: 666: 663: 660: 568: 548: 524: 500: 497: 494: 460: 457: 454: 451: 446: 443: 440: 437: 432: 429: 426: 418: 415: 412: 409: 406: 403: 400: 398: 394: 389: 388: 385: 382: 379: 374: 371: 368: 360: 357: 354: 351: 348: 345: 342: 340: 336: 331: 330: 327: 322: 319: 316: 308: 305: 302: 299: 296: 293: 290: 287: 284: 282: 278: 275: 272: 267: 266: 232: 229: 194:Hindley-Milner 188: 187: 170: 169: 131: 129: 122: 115: 114: 69: 67: 60: 55: 29: 28: 26: 19: 13: 10: 9: 6: 4: 3: 2: 1342: 1331: 1328: 1327: 1325: 1315: 1312: 1310: 1306: 1303: 1302: 1298: 1293: 1289: 1286: 1285: 1280: 1276: 1273: 1269: 1266: 1263: 1260: 1257: 1255:. PhD thesis. 1254: 1250: 1247: 1246: 1238: 1234: 1230: 1226: 1222: 1218: 1214: 1210: 1206: 1199: 1197: 1195: 1191: 1184: 1180: 1177: 1176: 1172: 1084: 1081: 1005: 1002: 1001:free variable 986: 947: 941: 926: 925: 924: 921: 877: 869: 861: 859: 676: 670: 664: 661: 566: 564: 482: 477: 441: 416: 410: 407: 401: 399: 383: 358: 352: 349: 343: 341: 306: 297: 294: 291: 285: 283: 256: 254: 250: 246: 242: 238: 230: 228: 226: 222: 221:non-expansive 218: 215: 211: 207: 203: 199: 195: 184: 181: 166: 163: 155: 145: 141: 135: 132:This article 130: 121: 120: 111: 108: 100: 90: 86: 80: 79: 73: 68: 59: 58: 53: 51: 44: 43: 38: 37: 32: 27: 18: 17: 1282: 1252: 1212: 1208: 1089:is typed as 922: 867: 865: 646: 478: 257: 249:typing rules 234: 220: 210:declarations 205: 191: 176: 158: 149: 138:Please help 133: 103: 94: 75: 47: 40: 34: 33:Please help 30: 1080:unification 245:type safety 225:type safety 217:generalized 208:means that 89:introducing 1270:My Hoang, 1249:Mads Tofte 1185:References 198:imperative 72:references 36:improve it 1229:1573-0557 1110:→ 1034:→ 987:α 948:α 945:→ 942:α 878:λ 807:→ 732:→ 677:α 674:→ 671:α 662:α 659:∀ 563:unit type 481:semantics 445:→ 442:α 439:→ 417:α 408:α 405:∀ 384:α 381:→ 359:α 350:α 347:∀ 307:α 301:→ 298:α 292:α 289:∀ 212:are only 152:July 2018 97:July 2018 42:talk page 1324:Category 1307:— 1251:(1988). 1237:19286877 1173:See also 856:!c true 235:In the 85:improve 1281:". In 1235:  1227:  1053:  954:  927:First 829:  780:, and 751:  683:  420:  362:  310:  74:, but 1309:MLton 1233:S2CID 999:is a 621:=> 594:=> 1225:ISSN 1078:via 639:true 1217:doi 642:end 582:ref 573:val 570:let 142:by 1326:: 1231:. 1223:. 1211:. 1207:. 1193:^ 1087:!c 858:. 636:!c 633:); 615:fn 609::= 603:in 588:fn 547::= 483:: 393::= 253:ML 227:. 202:ML 45:. 1294:. 1239:. 1219:: 1213:8 1154:l 1151:o 1148:o 1145:b 1121:t 1118:n 1115:i 1105:t 1102:n 1099:i 1082:. 1064:f 1061:e 1058:r 1050:) 1045:t 1042:n 1039:i 1029:t 1026:n 1023:i 1018:( 1008:c 965:f 962:e 959:r 951:) 939:( 929:c 906:f 903:e 900:r 840:f 837:e 834:r 826:) 821:l 818:o 815:o 812:b 802:l 799:o 796:o 793:b 788:( 762:f 759:e 756:r 748:) 743:t 740:n 737:i 727:t 724:n 721:i 716:( 694:f 691:e 688:r 680:) 668:( 665:. 649:c 630:1 627:+ 624:x 618:x 612:( 606:c 600:) 597:x 591:x 585:( 579:= 576:c 523:! 499:f 496:e 493:r 459:t 456:i 453:n 450:u 436:) 431:f 428:e 425:r 414:( 411:. 402:: 378:) 373:f 370:e 367:r 356:( 353:. 344:: 335:! 326:) 321:f 318:e 315:r 304:( 295:. 286:: 277:f 274:e 271:r 183:) 177:( 165:) 159:( 154:) 150:( 146:. 136:. 110:) 104:( 99:) 95:( 81:. 52:) 48:(

Index

improve it
talk page
Learn how and when to remove these messages
references
inline citations
improve
introducing
Learn how and when to remove this message
improve the article
providing more context for the reader
Learn how and when to remove this message
Learn how and when to remove this message
Hindley-Milner
imperative
ML
declarations
polymorphically
generalized
type safety
Hindley–Milner type system
parametric polymorphism
type safety
typing rules
ML
semantics
unit type
free variable
unification
Hindley–Milner type inference

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.

↑