Knowledge (XXG)

Functor (functional programming)

Source đź“ť

27: 305:
by values of parameterized data types. Modifiable computations are modeled by allowing a pure function to be applied to values of the "inner" type, thus creating the new overall value which represents the modified computation (which might yet to be run).
704: 1229: 1342: 1254: 1027: 1337: 1202: 826: 19:
This article is about the design pattern for mapping functions over a generic type. For the term "functor" as used in C++, see
1010: 920: 298: 294: 1050: 1020: 1015: 697: 222: 218: 1347: 1295: 1133: 910: 1118: 1113: 940: 1158: 1123: 1090: 740: 690: 955: 1060: 1032: 970: 935: 871: 713: 1037: 965: 915: 750: 55: 39: 633: 1316: 1219: 1065: 1045: 990: 667: 302: 139:, which state that the mapping operation preserves the identity function and composition of functions: 1128: 1085: 1080: 1070: 980: 211: 1168: 1153: 1148: 1005: 890: 836: 586: 290: 1290: 1269: 1178: 1075: 925: 818: 770: 732: 960: 803: 793: 788: 760: 755: 677: 1259: 1000: 945: 866: 856: 846: 841: 668:
Chapter 11 Functors, Applicative Functors and Monoids in Learn You a Haskell for Great Good!
1249: 1195: 1173: 950: 905: 876: 851: 831: 778: 745: 721: 20: 301:, all of which build atop a canonical functor structure. Functors are useful in modeling 1234: 1095: 798: 783: 47: 672: 1331: 1055: 900: 861: 808: 1311: 1274: 1163: 1138: 930: 662: 59: 1264: 1239: 1224: 1143: 975: 608: 26: 67: 1244: 682: 34:
to a binary tree of integers increments each integer in the tree by one.
581: 63: 51: 314:
In Haskell, lists are a simple example of a functor. We may implement
128:
This declaration says that any type of Functor must support a method
25: 686: 132:, which maps a function over the element(s) of the Functor. 678:
Section about Functor in lemastero/scala_typeclassopedia
289:
Functors form a base for more complex abstractions like
382:
A binary tree may similarly be described as a functor:
62:
without changing the structure of the generic type. In
1304: 1283: 1212: 1187: 1104: 989: 889: 817: 769: 731: 720: 569: 565: 561: 557: 553: 549: 545: 541: 537: 315: 31: 663:Section about Functor in Haskell Typeclassopedia 698: 16:Design pattern in pure functional programming 8: 728: 705: 691: 683: 673:Documentation for Functor in Cats library 599: 135:Functors in Haskell should also obey 7: 52:the definition from category theory 14: 1203:Enterprise Integration Patterns 66:this idea can be captured in a 564:, adding 1 to each element of 1: 1296:Portland Pattern Repository 589:, a special type of functor 54:that allows one to apply a 1364: 582:Functor in category theory 18: 536:If we have a binary tree 1343:Software design patterns 921:Event-based asynchronous 714:Software design patterns 640:. University of Maryland 384: 320: 227: 141: 72: 827:Chain of responsibility 1338:Functional programming 966:Scheduled-task pattern 916:Double-checked locking 40:functional programming 35: 1317:Architectural pattern 1220:Christopher Alexander 29: 1129:Dependency injection 1086:Inversion of control 1081:Data transfer object 981:Thread-local storage 568:can be expressed as 552:to every element of 212:function composition 1134:Intercepting filter 609:"Functor > Laws" 587:Applicative functor 542:f :: a -> b 291:Applicative Functor 58:to values inside a 1348:Programming idioms 1291:The Hillside Group 1076:Data access object 926:Guarded suspension 911:Binding properties 556:. For example, if 303:functional effects 36: 1325: 1324: 1119:Business delegate 1051:Publish–subscribe 885: 884: 638:Functional Pearls 538:tr :: Tree a 1355: 1124:Composite entity 1001:Front controller 741:Abstract factory 729: 707: 700: 693: 684: 650: 649: 647: 645: 630: 624: 623: 621: 619: 604: 571: 567: 563: 559: 555: 551: 547: 543: 539: 532: 529: 526: 523: 520: 517: 514: 511: 508: 505: 502: 499: 496: 493: 490: 487: 484: 481: 478: 475: 472: 469: 466: 463: 460: 457: 454: 451: 448: 445: 442: 439: 436: 433: 430: 427: 424: 421: 418: 415: 412: 409: 406: 403: 400: 397: 394: 391: 388: 378: 375: 372: 369: 366: 363: 360: 357: 354: 351: 348: 345: 342: 339: 336: 333: 330: 327: 324: 317: 285: 282: 279: 276: 273: 270: 267: 264: 261: 258: 255: 252: 249: 246: 243: 240: 237: 234: 231: 209: 202: 199: 196: 193: 190: 187: 184: 181: 178: 175: 172: 169: 166: 163: 160: 157: 154: 151: 148: 145: 131: 124: 121: 118: 115: 112: 109: 106: 103: 100: 97: 94: 91: 88: 85: 82: 79: 76: 33: 1363: 1362: 1358: 1357: 1356: 1354: 1353: 1352: 1328: 1327: 1326: 1321: 1300: 1279: 1270:Douglas Schmidt 1250:Ward Cunningham 1208: 1196:Design Patterns 1183: 1174:Method chaining 1106: 1100: 1061:Service locator 992: 985: 956:Read–write lock 892: 881: 872:Template method 813: 765: 723: 716: 711: 659: 654: 653: 643: 641: 632: 631: 627: 617: 615: 607:Yorgey, Brent. 606: 605: 601: 596: 578: 544:, the function 540:and a function 534: 533: 530: 527: 524: 521: 518: 515: 512: 509: 506: 503: 500: 497: 494: 491: 488: 485: 482: 479: 476: 473: 470: 467: 464: 461: 458: 455: 452: 449: 446: 443: 440: 437: 434: 431: 428: 425: 422: 419: 416: 413: 410: 407: 404: 401: 398: 395: 392: 389: 386: 380: 379: 376: 373: 370: 367: 364: 361: 358: 355: 352: 349: 346: 343: 340: 337: 334: 331: 328: 325: 322: 312: 287: 286: 283: 280: 277: 274: 271: 268: 265: 262: 259: 256: 253: 250: 247: 244: 241: 238: 235: 232: 229: 207: 204: 203: 200: 197: 194: 191: 188: 185: 182: 179: 176: 173: 170: 167: 164: 161: 158: 155: 152: 149: 146: 143: 129: 126: 125: 122: 119: 116: 113: 110: 107: 104: 101: 98: 95: 92: 89: 86: 83: 80: 77: 74: 24: 21:function object 17: 12: 11: 5: 1361: 1359: 1351: 1350: 1345: 1340: 1330: 1329: 1323: 1322: 1320: 1319: 1314: 1308: 1306: 1302: 1301: 1299: 1298: 1293: 1287: 1285: 1281: 1280: 1278: 1277: 1272: 1267: 1262: 1257: 1252: 1247: 1242: 1237: 1235:John Vlissides 1232: 1227: 1222: 1216: 1214: 1210: 1209: 1207: 1206: 1199: 1191: 1189: 1185: 1184: 1182: 1181: 1176: 1171: 1166: 1161: 1156: 1151: 1146: 1141: 1136: 1131: 1126: 1121: 1116: 1110: 1108: 1102: 1101: 1099: 1098: 1093: 1088: 1083: 1078: 1073: 1068: 1063: 1058: 1053: 1048: 1043: 1035: 1030: 1025: 1024: 1023: 1018: 1008: 1003: 997: 995: 987: 986: 984: 983: 978: 973: 968: 963: 958: 953: 948: 943: 938: 933: 928: 923: 918: 913: 908: 903: 897: 895: 887: 886: 883: 882: 880: 879: 874: 869: 864: 859: 854: 849: 844: 839: 834: 829: 823: 821: 815: 814: 812: 811: 806: 801: 796: 791: 786: 781: 775: 773: 767: 766: 764: 763: 758: 753: 751:Factory method 748: 743: 737: 735: 726: 718: 717: 712: 710: 709: 702: 695: 687: 681: 680: 675: 670: 665: 658: 657:External links 655: 652: 651: 625: 598: 597: 595: 592: 591: 590: 584: 577: 574: 385: 321: 311: 308: 228: 142: 73: 48:design pattern 15: 13: 10: 9: 6: 4: 3: 2: 1360: 1349: 1346: 1344: 1341: 1339: 1336: 1335: 1333: 1318: 1315: 1313: 1310: 1309: 1307: 1303: 1297: 1294: 1292: 1289: 1288: 1286: 1282: 1276: 1273: 1271: 1268: 1266: 1263: 1261: 1260:Robert Martin 1258: 1256: 1255:Martin Fowler 1253: 1251: 1248: 1246: 1243: 1241: 1238: 1236: 1233: 1231: 1230:Ralph Johnson 1228: 1226: 1223: 1221: 1218: 1217: 1215: 1211: 1205: 1204: 1200: 1198: 1197: 1193: 1192: 1190: 1186: 1180: 1177: 1175: 1172: 1170: 1167: 1165: 1162: 1160: 1157: 1155: 1152: 1150: 1147: 1145: 1142: 1140: 1137: 1135: 1132: 1130: 1127: 1125: 1122: 1120: 1117: 1115: 1112: 1111: 1109: 1103: 1097: 1094: 1092: 1089: 1087: 1084: 1082: 1079: 1077: 1074: 1072: 1069: 1067: 1066:Active record 1064: 1062: 1059: 1057: 1056:Naked objects 1054: 1052: 1049: 1047: 1046:Specification 1044: 1042: 1040: 1036: 1034: 1031: 1029: 1026: 1022: 1019: 1017: 1014: 1013: 1012: 1009: 1007: 1004: 1002: 999: 998: 996: 994: 991:Architectural 988: 982: 979: 977: 974: 972: 969: 967: 964: 962: 959: 957: 954: 952: 949: 947: 944: 942: 939: 937: 934: 932: 929: 927: 924: 922: 919: 917: 914: 912: 909: 907: 904: 902: 901:Active object 899: 898: 896: 894: 888: 878: 875: 873: 870: 868: 865: 863: 860: 858: 855: 853: 850: 848: 845: 843: 840: 838: 835: 833: 830: 828: 825: 824: 822: 820: 816: 810: 807: 805: 802: 800: 797: 795: 792: 790: 787: 785: 782: 780: 777: 776: 774: 772: 768: 762: 759: 757: 754: 752: 749: 747: 744: 742: 739: 738: 736: 734: 730: 727: 725: 719: 715: 708: 703: 701: 696: 694: 689: 688: 685: 679: 676: 674: 671: 669: 666: 664: 661: 660: 656: 639: 635: 629: 626: 614: 610: 603: 600: 593: 588: 585: 583: 580: 579: 575: 573: 570:fmap (+ 1) tr 383: 319: 309: 307: 304: 300: 296: 292: 226: 225:can be used: 224: 220: 215: 213: 140: 138: 133: 71: 69: 65: 61: 57: 53: 49: 45: 41: 28: 22: 1312:Anti-pattern 1275:Linda Rising 1201: 1194: 1139:Lazy loading 1071:Identity map 1038: 722:Gang of Four 642:. Retrieved 637: 628: 616:. Retrieved 612: 602: 535: 381: 313: 288: 216: 205: 137:functor laws 136: 134: 127: 60:generic type 50:inspired by 43: 37: 1284:Communities 1265:Jim Coplien 1240:Grady Booch 1225:Erich Gamma 1169:Type tunnel 1154:Object pool 1149:Null object 1144:Mock object 1006:Interceptor 976:Thread pool 891:Concurrency 837:Interpreter 644:12 December 613:HaskellWiki 548:will apply 210:stands for 1332:Categories 1179:Delegation 1114:Blackboard 819:Behavioral 771:Structural 733:Creational 634:"Functors" 594:References 68:type class 1245:Kent Beck 971:Semaphore 961:Scheduler 804:Flyweight 794:Decorator 789:Composite 761:Singleton 756:Prototype 546:fmap f tr 32:fmap (+1) 30:Applying 1305:See also 1107:patterns 993:patterns 946:Proactor 893:patterns 867:Strategy 857:Observer 847:Mediator 842:Iterator 724:patterns 576:See also 435:instance 310:Examples 56:function 1159:Servant 1091:Model 2 951:Reactor 941:Monitor 906:Balking 877:Visitor 852:Memento 832:Command 779:Adapter 746:Builder 618:17 June 438:Functor 299:Comonad 233:Functor 206:(where 78:Functor 64:Haskell 44:functor 1213:People 1096:Broker 799:Facade 784:Bridge 297:, and 1188:Books 1105:Other 1041:-tier 862:State 809:Proxy 444:where 295:Monad 272:=> 230:trait 223:trait 219:Scala 117:-> 108:-> 99:-> 84:where 75:class 46:is a 1164:Twin 1021:MVVM 936:Lock 931:Join 646:2022 620:2023 522:fmap 507:fmap 489:Node 471:Node 462:fmap 459:Leaf 453:Leaf 447:fmap 441:Tree 426:Tree 414:Tree 405:Node 399:Leaf 390:Tree 387:data 371:fmap 332:fmap 323:fmap 316:fmap 195:fmap 180:fmap 156:fmap 144:fmap 130:fmap 87:fmap 42:, a 1033:ECS 1028:ADR 1016:MVP 1011:MVC 562:Int 560:is 318:as 245:map 242:def 217:In 214:). 38:In 1334:: 636:. 611:. 572:. 566:tr 554:tr 377:xs 347:xs 293:, 278:): 260:)( 221:a 153:id 147:id 90::: 70:: 1039:n 706:e 699:t 692:v 648:. 622:. 558:a 550:f 531:) 528:r 525:f 519:( 516:) 513:l 510:f 504:( 501:) 498:x 495:f 492:( 486:= 483:) 480:r 477:l 474:x 468:( 465:f 456:= 450:f 432:) 429:a 423:( 420:) 417:a 411:( 408:a 402:| 396:= 393:a 374:f 368:: 365:) 362:x 359:f 356:( 353:= 350:) 344:: 341:x 338:( 335:f 329:= 326:f 284:} 281:F 275:B 269:A 266:: 263:f 257:F 254:: 251:a 248:( 239:{ 236:] 208:. 201:) 198:h 192:( 189:. 186:) 183:g 177:( 174:= 171:) 168:h 165:. 162:g 159:( 150:= 123:b 120:f 114:a 111:f 105:) 102:b 96:a 93:( 81:f 23:.

Index

function object

functional programming
design pattern
the definition from category theory
function
generic type
Haskell
type class
function composition
Scala
trait
Applicative Functor
Monad
Comonad
functional effects
Functor in category theory
Applicative functor
"Functor > Laws"
"Functors"
Section about Functor in Haskell Typeclassopedia
Chapter 11 Functors, Applicative Functors and Monoids in Learn You a Haskell for Great Good!
Documentation for Functor in Cats library
Section about Functor in lemastero/scala_typeclassopedia
v
t
e
Software design patterns
Gang of Four
patterns

Creational

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

↑