/usr/share/doc/libghc-basic-prelude-doc/html/basic-prelude.txt is in libghc-basic-prelude-doc 0.6.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 | -- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | An enhanced core prelude; a common foundation for alternate preludes.
--
-- The premise of <tt>basic-prelude</tt> is that there are a lot of very
-- commonly desired features missing from the standard <tt>Prelude</tt>,
-- such as commonly used operators (<tt><$></tt> and
-- <tt>>=></tt>, for instance) and imports for common datatypes
-- (e.g., <tt>ByteString</tt> and <tt>Vector</tt>). At the same time,
-- there are lots of other components which are more debatable, such as
-- providing polymorphic versions of common functions.
--
-- So <tt>basic-prelude</tt> is intended to give a common foundation for
-- a number of alternate preludes. The package provides two modules:
-- <tt>CorePrelude</tt> provides the common ground for other preludes to
-- build on top of, while <tt>BasicPrelude</tt> exports
-- <tt>CorePrelude</tt> together with commonly used list functions to
-- provide a drop-in replacement for the standard <tt>Prelude</tt>.
--
-- Users wishing to have an improved <tt>Prelude</tt> can use
-- <tt>BasicPrelude</tt>. Developers wishing to create a new prelude
-- should use <tt>CorePrelude</tt>.
@package basic-prelude
@version 0.6.1
module CorePrelude
-- | Application operator. This operator is redundant, since ordinary
-- application <tt>(f x)</tt> means the same as <tt>(f <a>$</a> x)</tt>.
-- However, <a>$</a> has low, right-associative binding precedence, so it
-- sometimes allows parentheses to be omitted; for example:
--
-- <pre>
-- f $ g $ h x = f (g (h x))
-- </pre>
--
-- It is also useful in higher-order situations, such as <tt><a>map</a>
-- (<a>$</a> 0) xs</tt>, or <tt><a>zipWith</a> (<a>$</a>) fs xs</tt>.
($) :: (a -> b) -> a -> b
infixr 0 $
-- | Strict (call-by-value) application operator. It takes a function and
-- an argument, evaluates the argument to weak head normal form (WHNF),
-- then calls the function with that value.
($!) :: (a -> b) -> a -> b
infixr 0 $!
-- | Boolean "and"
(&&) :: Bool -> Bool -> Bool
infixr 3 &&
-- | Boolean "or"
(||) :: Bool -> Bool -> Bool
infixr 2 ||
-- | morphism composition
(.) :: Category k cat => forall (b :: k) (c :: k) (a :: k). cat b c -> cat a b -> cat a c
-- | Boolean "not"
not :: Bool -> Bool
-- | <a>otherwise</a> is defined as the value <a>True</a>. It helps to make
-- guards more readable. eg.
--
-- <pre>
-- f x | x < 0 = ...
-- | otherwise = ...
-- </pre>
otherwise :: Bool
-- | Extract the first component of a pair.
fst :: (a, b) -> a
-- | Extract the second component of a pair.
snd :: (a, b) -> b
-- | the identity morphism
id :: Category k cat => forall (a :: k). cat a a
-- | The <a>maybe</a> function takes a default value, a function, and a
-- <a>Maybe</a> value. If the <a>Maybe</a> value is <a>Nothing</a>, the
-- function returns the default value. Otherwise, it applies the function
-- to the value inside the <a>Just</a> and returns the result.
--
-- <h4><b>Examples</b></h4>
--
-- Basic usage:
--
-- <pre>
-- >>> maybe False odd (Just 3)
-- True
-- </pre>
--
-- <pre>
-- >>> maybe False odd Nothing
-- False
-- </pre>
--
-- Read an integer from a string using <tt>readMaybe</tt>. If we succeed,
-- return twice the integer; that is, apply <tt>(*2)</tt> to it. If
-- instead we fail to parse an integer, return <tt>0</tt> by default:
--
-- <pre>
-- >>> import Text.Read ( readMaybe )
--
-- >>> maybe 0 (*2) (readMaybe "5")
-- 10
--
-- >>> maybe 0 (*2) (readMaybe "")
-- 0
-- </pre>
--
-- Apply <tt>show</tt> to a <tt>Maybe Int</tt>. If we have <tt>Just
-- n</tt>, we want to show the underlying <a>Int</a> <tt>n</tt>. But if
-- we have <a>Nothing</a>, we return the empty string instead of (for
-- example) "Nothing":
--
-- <pre>
-- >>> maybe "" show (Just 5)
-- "5"
--
-- >>> maybe "" show Nothing
-- ""
-- </pre>
maybe :: b -> (a -> b) -> Maybe a -> b
-- | Case analysis for the <a>Either</a> type. If the value is
-- <tt><a>Left</a> a</tt>, apply the first function to <tt>a</tt>; if it
-- is <tt><a>Right</a> b</tt>, apply the second function to <tt>b</tt>.
--
-- <h4><b>Examples</b></h4>
--
-- We create two values of type <tt><a>Either</a> <a>String</a>
-- <a>Int</a></tt>, one using the <a>Left</a> constructor and another
-- using the <a>Right</a> constructor. Then we apply "either" the
-- <tt>length</tt> function (if we have a <a>String</a>) or the
-- "times-two" function (if we have an <a>Int</a>):
--
-- <pre>
-- >>> let s = Left "foo" :: Either String Int
--
-- >>> let n = Right 3 :: Either String Int
--
-- >>> either length (*2) s
-- 3
--
-- >>> either length (*2) n
-- 6
-- </pre>
either :: (a -> c) -> (b -> c) -> Either a b -> c
-- | <tt><a>flip</a> f</tt> takes its (first) two arguments in the reverse
-- order of <tt>f</tt>.
flip :: (a -> b -> c) -> b -> a -> c
-- | <tt>const x</tt> is a unary function which evaluates to <tt>x</tt> for
-- all inputs.
--
-- For instance,
--
-- <pre>
-- >>> map (const 42) [0..3]
-- [42,42,42,42]
-- </pre>
const :: a -> b -> a
-- | <a>error</a> stops execution and displays an error message.
error :: HasCallStack => [Char] -> a
putStr :: MonadIO m => Text -> m ()
putStrLn :: MonadIO m => Text -> m ()
print :: (MonadIO m, Show a) => a -> m ()
getArgs :: MonadIO m => m [Text]
-- | <tt>error</tt> applied to <tt>Text</tt>
--
-- Since 0.4.1
terror :: Text -> a
odd :: Integral a => a -> Bool
even :: Integral a => a -> Bool
-- | <a>uncurry</a> converts a curried function to a function on pairs.
uncurry :: (a -> b -> c) -> (a, b) -> c
-- | <a>curry</a> converts an uncurried function to a curried function.
curry :: ((a, b) -> c) -> a -> b -> c
-- | Swap the components of a pair.
swap :: (a, b) -> (b, a)
-- | <tt><a>until</a> p f</tt> yields the result of applying <tt>f</tt>
-- until <tt>p</tt> holds.
until :: (a -> Bool) -> (a -> a) -> a -> a
-- | <a>asTypeOf</a> is a type-restricted version of <a>const</a>. It is
-- usually used as an infix operator, and its typing forces its first
-- argument (which is usually overloaded) to have the same type as the
-- second.
asTypeOf :: a -> a -> a
-- | A special case of <a>error</a>. It is expected that compilers will
-- recognize this and insert error messages which are more appropriate to
-- the context in which <a>undefined</a> appears.
undefined :: HasCallStack => a
-- | The value of <tt>seq a b</tt> is bottom if <tt>a</tt> is bottom, and
-- otherwise equal to <tt>b</tt>. <tt>seq</tt> is usually introduced to
-- improve performance by avoiding unneeded laziness.
--
-- A note on evaluation order: the expression <tt>seq a b</tt> does
-- <i>not</i> guarantee that <tt>a</tt> will be evaluated before
-- <tt>b</tt>. The only guarantee given by <tt>seq</tt> is that the both
-- <tt>a</tt> and <tt>b</tt> will be evaluated before <tt>seq</tt>
-- returns a value. In particular, this means that <tt>b</tt> may be
-- evaluated before <tt>a</tt>. If you need to guarantee a specific order
-- of evaluation, you must use the function <tt>pseq</tt> from the
-- "parallel" package.
seq :: a -> b -> b
-- | The <a>Ord</a> class is used for totally ordered datatypes.
--
-- Instances of <a>Ord</a> can be derived for any user-defined datatype
-- whose constituent types are in <a>Ord</a>. The declared order of the
-- constructors in the data declaration determines the ordering in
-- derived <a>Ord</a> instances. The <a>Ordering</a> datatype allows a
-- single comparison to determine the precise ordering of two objects.
--
-- Minimal complete definition: either <a>compare</a> or <a><=</a>.
-- Using <a>compare</a> can be more efficient for complex types.
class Eq a => Ord a
compare :: a -> a -> Ordering
(<) :: a -> a -> Bool
(<=) :: a -> a -> Bool
(>) :: a -> a -> Bool
(>=) :: a -> a -> Bool
max :: a -> a -> a
min :: a -> a -> a
-- | The <a>Eq</a> class defines equality (<a>==</a>) and inequality
-- (<a>/=</a>). All the basic datatypes exported by the <a>Prelude</a>
-- are instances of <a>Eq</a>, and <a>Eq</a> may be derived for any
-- datatype whose constituents are also instances of <a>Eq</a>.
--
-- Minimal complete definition: either <a>==</a> or <a>/=</a>.
class Eq a
(==) :: a -> a -> Bool
(/=) :: a -> a -> Bool
-- | The <a>Bounded</a> class is used to name the upper and lower limits of
-- a type. <a>Ord</a> is not a superclass of <a>Bounded</a> since types
-- that are not totally ordered may also have upper and lower bounds.
--
-- The <a>Bounded</a> class may be derived for any enumeration type;
-- <a>minBound</a> is the first constructor listed in the <tt>data</tt>
-- declaration and <a>maxBound</a> is the last. <a>Bounded</a> may also
-- be derived for single-constructor datatypes whose constituent types
-- are in <a>Bounded</a>.
class Bounded a
minBound :: a
maxBound :: a
-- | Class <a>Enum</a> defines operations on sequentially ordered types.
--
-- The <tt>enumFrom</tt>... methods are used in Haskell's translation of
-- arithmetic sequences.
--
-- Instances of <a>Enum</a> may be derived for any enumeration type
-- (types whose constructors have no fields). The nullary constructors
-- are assumed to be numbered left-to-right by <a>fromEnum</a> from
-- <tt>0</tt> through <tt>n-1</tt>. See Chapter 10 of the <i>Haskell
-- Report</i> for more details.
--
-- For any type that is an instance of class <a>Bounded</a> as well as
-- <a>Enum</a>, the following should hold:
--
-- <ul>
-- <li>The calls <tt><a>succ</a> <a>maxBound</a></tt> and <tt><a>pred</a>
-- <a>minBound</a></tt> should result in a runtime error.</li>
-- <li><a>fromEnum</a> and <a>toEnum</a> should give a runtime error if
-- the result value is not representable in the result type. For example,
-- <tt><a>toEnum</a> 7 :: <a>Bool</a></tt> is an error.</li>
-- <li><a>enumFrom</a> and <a>enumFromThen</a> should be defined with an
-- implicit bound, thus:</li>
-- </ul>
--
-- <pre>
-- enumFrom x = enumFromTo x maxBound
-- enumFromThen x y = enumFromThenTo x y bound
-- where
-- bound | fromEnum y >= fromEnum x = maxBound
-- | otherwise = minBound
-- </pre>
class Enum a
-- | the successor of a value. For numeric types, <a>succ</a> adds 1.
succ :: a -> a
-- | the predecessor of a value. For numeric types, <a>pred</a> subtracts
-- 1.
pred :: a -> a
-- | Convert from an <a>Int</a>.
toEnum :: Int -> a
-- | Convert to an <a>Int</a>. It is implementation-dependent what
-- <a>fromEnum</a> returns when applied to a value that is too large to
-- fit in an <a>Int</a>.
fromEnum :: a -> Int
-- | Used in Haskell's translation of <tt>[n..]</tt>.
enumFrom :: a -> [a]
-- | Used in Haskell's translation of <tt>[n,n'..]</tt>.
enumFromThen :: a -> a -> [a]
-- | Used in Haskell's translation of <tt>[n..m]</tt>.
enumFromTo :: a -> a -> [a]
-- | Used in Haskell's translation of <tt>[n,n'..m]</tt>.
enumFromThenTo :: a -> a -> a -> [a]
-- | Conversion of values to readable <a>String</a>s.
--
-- Derived instances of <a>Show</a> have the following properties, which
-- are compatible with derived instances of <a>Read</a>:
--
-- <ul>
-- <li>The result of <a>show</a> is a syntactically correct Haskell
-- expression containing only constants, given the fixity declarations in
-- force at the point where the type is declared. It contains only the
-- constructor names defined in the data type, parentheses, and spaces.
-- When labelled constructor fields are used, braces, commas, field
-- names, and equal signs are also used.</li>
-- <li>If the constructor is defined to be an infix operator, then
-- <a>showsPrec</a> will produce infix applications of the
-- constructor.</li>
-- <li>the representation will be enclosed in parentheses if the
-- precedence of the top-level constructor in <tt>x</tt> is less than
-- <tt>d</tt> (associativity is ignored). Thus, if <tt>d</tt> is
-- <tt>0</tt> then the result is never surrounded in parentheses; if
-- <tt>d</tt> is <tt>11</tt> it is always surrounded in parentheses,
-- unless it is an atomic expression.</li>
-- <li>If the constructor is defined using record syntax, then
-- <a>show</a> will produce the record-syntax form, with the fields given
-- in the same order as the original declaration.</li>
-- </ul>
--
-- For example, given the declarations
--
-- <pre>
-- infixr 5 :^:
-- data Tree a = Leaf a | Tree a :^: Tree a
-- </pre>
--
-- the derived instance of <a>Show</a> is equivalent to
--
-- <pre>
-- instance (Show a) => Show (Tree a) where
--
-- showsPrec d (Leaf m) = showParen (d > app_prec) $
-- showString "Leaf " . showsPrec (app_prec+1) m
-- where app_prec = 10
--
-- showsPrec d (u :^: v) = showParen (d > up_prec) $
-- showsPrec (up_prec+1) u .
-- showString " :^: " .
-- showsPrec (up_prec+1) v
-- where up_prec = 5
-- </pre>
--
-- Note that right-associativity of <tt>:^:</tt> is ignored. For example,
--
-- <ul>
-- <li><tt><a>show</a> (Leaf 1 :^: Leaf 2 :^: Leaf 3)</tt> produces the
-- string <tt>"Leaf 1 :^: (Leaf 2 :^: Leaf 3)"</tt>.</li>
-- </ul>
class Show a
-- | Parsing of <a>String</a>s, producing values.
--
-- Derived instances of <a>Read</a> make the following assumptions, which
-- derived instances of <a>Show</a> obey:
--
-- <ul>
-- <li>If the constructor is defined to be an infix operator, then the
-- derived <a>Read</a> instance will parse only infix applications of the
-- constructor (not the prefix form).</li>
-- <li>Associativity is not used to reduce the occurrence of parentheses,
-- although precedence may be.</li>
-- <li>If the constructor is defined using record syntax, the derived
-- <a>Read</a> will parse only the record-syntax form, and furthermore,
-- the fields must be given in the same order as the original
-- declaration.</li>
-- <li>The derived <a>Read</a> instance allows arbitrary Haskell
-- whitespace between tokens of the input string. Extra parentheses are
-- also allowed.</li>
-- </ul>
--
-- For example, given the declarations
--
-- <pre>
-- infixr 5 :^:
-- data Tree a = Leaf a | Tree a :^: Tree a
-- </pre>
--
-- the derived instance of <a>Read</a> in Haskell 2010 is equivalent to
--
-- <pre>
-- instance (Read a) => Read (Tree a) where
--
-- readsPrec d r = readParen (d > app_prec)
-- (\r -> [(Leaf m,t) |
-- ("Leaf",s) <- lex r,
-- (m,t) <- readsPrec (app_prec+1) s]) r
--
-- ++ readParen (d > up_prec)
-- (\r -> [(u:^:v,w) |
-- (u,s) <- readsPrec (up_prec+1) r,
-- (":^:",t) <- lex s,
-- (v,w) <- readsPrec (up_prec+1) t]) r
--
-- where app_prec = 10
-- up_prec = 5
-- </pre>
--
-- Note that right-associativity of <tt>:^:</tt> is unused.
--
-- The derived instance in GHC is equivalent to
--
-- <pre>
-- instance (Read a) => Read (Tree a) where
--
-- readPrec = parens $ (prec app_prec $ do
-- Ident "Leaf" <- lexP
-- m <- step readPrec
-- return (Leaf m))
--
-- +++ (prec up_prec $ do
-- u <- step readPrec
-- Symbol ":^:" <- lexP
-- v <- step readPrec
-- return (u :^: v))
--
-- where app_prec = 10
-- up_prec = 5
--
-- readListPrec = readListPrecDefault
-- </pre>
class Read a
-- | The <a>Functor</a> class is used for types that can be mapped over.
-- Instances of <a>Functor</a> should satisfy the following laws:
--
-- <pre>
-- fmap id == id
-- fmap (f . g) == fmap f . fmap g
-- </pre>
--
-- The instances of <a>Functor</a> for lists, <a>Maybe</a> and <a>IO</a>
-- satisfy these laws.
class Functor (f :: * -> *)
fmap :: (a -> b) -> f a -> f b
-- | Replace all locations in the input with the same value. The default
-- definition is <tt><a>fmap</a> . <a>const</a></tt>, but this may be
-- overridden with a more efficient version.
(<$) :: a -> f b -> f a
-- | The <a>Monad</a> class defines the basic operations over a
-- <i>monad</i>, a concept from a branch of mathematics known as
-- <i>category theory</i>. From the perspective of a Haskell programmer,
-- however, it is best to think of a monad as an <i>abstract datatype</i>
-- of actions. Haskell's <tt>do</tt> expressions provide a convenient
-- syntax for writing monadic expressions.
--
-- Instances of <a>Monad</a> should satisfy the following laws:
--
-- <ul>
-- <li><pre><a>return</a> a <a>>>=</a> k = k a</pre></li>
-- <li><pre>m <a>>>=</a> <a>return</a> = m</pre></li>
-- <li><pre>m <a>>>=</a> (x -> k x <a>>>=</a> h) = (m
-- <a>>>=</a> k) <a>>>=</a> h</pre></li>
-- </ul>
--
-- Furthermore, the <a>Monad</a> and <a>Applicative</a> operations should
-- relate as follows:
--
-- <ul>
-- <li><pre><a>pure</a> = <a>return</a></pre></li>
-- <li><pre>(<a><*></a>) = <a>ap</a></pre></li>
-- </ul>
--
-- The above laws imply:
--
-- <ul>
-- <li><pre><a>fmap</a> f xs = xs <a>>>=</a> <a>return</a> .
-- f</pre></li>
-- <li><pre>(<a>>></a>) = (<a>*></a>)</pre></li>
-- </ul>
--
-- and that <a>pure</a> and (<a><*></a>) satisfy the applicative
-- functor laws.
--
-- The instances of <a>Monad</a> for lists, <a>Maybe</a> and <a>IO</a>
-- defined in the <a>Prelude</a> satisfy these laws.
class Applicative m => Monad (m :: * -> *)
-- | Sequentially compose two actions, passing any value produced by the
-- first as an argument to the second.
(>>=) :: m a -> (a -> m b) -> m b
-- | Sequentially compose two actions, discarding any value produced by the
-- first, like sequencing operators (such as the semicolon) in imperative
-- languages.
(>>) :: m a -> m b -> m b
-- | Inject a value into the monadic type.
return :: a -> m a
-- | Fail with a message. This operation is not part of the mathematical
-- definition of a monad, but is invoked on pattern-match failure in a
-- <tt>do</tt> expression.
--
-- As part of the MonadFail proposal (MFP), this function is moved to its
-- own class <tt>MonadFail</tt> (see <a>Control.Monad.Fail</a> for more
-- details). The definition here will be removed in a future release.
fail :: String -> m a
-- | Same as <a>>>=</a>, but with the arguments interchanged.
(=<<) :: Monad m => (a -> m b) -> m a -> m b
infixr 1 =<<
-- | Class for string-like datastructures; used by the overloaded string
-- extension (-XOverloadedStrings in GHC).
class IsString a
fromString :: String -> a
-- | Basic numeric class.
class Num a
(+) :: a -> a -> a
(-) :: a -> a -> a
(*) :: a -> a -> a
-- | Unary negation.
negate :: a -> a
-- | Absolute value.
abs :: a -> a
-- | Sign of a number. The functions <a>abs</a> and <a>signum</a> should
-- satisfy the law:
--
-- <pre>
-- abs x * signum x == x
-- </pre>
--
-- For real numbers, the <a>signum</a> is either <tt>-1</tt> (negative),
-- <tt>0</tt> (zero) or <tt>1</tt> (positive).
signum :: a -> a
-- | Conversion from an <a>Integer</a>. An integer literal represents the
-- application of the function <a>fromInteger</a> to the appropriate
-- value of type <a>Integer</a>, so such literals have type
-- <tt>(<a>Num</a> a) => a</tt>.
fromInteger :: Integer -> a
class (Num a, Ord a) => Real a
-- | the rational equivalent of its real argument with full precision
toRational :: a -> Rational
-- | Integral numbers, supporting integer division.
class (Real a, Enum a) => Integral a
-- | integer division truncated toward zero
quot :: a -> a -> a
-- | integer remainder, satisfying
--
-- <pre>
-- (x `quot` y)*y + (x `rem` y) == x
-- </pre>
rem :: a -> a -> a
-- | integer division truncated toward negative infinity
div :: a -> a -> a
-- | integer modulus, satisfying
--
-- <pre>
-- (x `div` y)*y + (x `mod` y) == x
-- </pre>
mod :: a -> a -> a
-- | simultaneous <a>quot</a> and <a>rem</a>
quotRem :: a -> a -> (a, a)
-- | simultaneous <a>div</a> and <a>mod</a>
divMod :: a -> a -> (a, a)
-- | conversion to <a>Integer</a>
toInteger :: a -> Integer
-- | Fractional numbers, supporting real division.
class Num a => Fractional a
-- | fractional division
(/) :: a -> a -> a
-- | reciprocal fraction
recip :: a -> a
-- | Conversion from a <a>Rational</a> (that is <tt><a>Ratio</a>
-- <a>Integer</a></tt>). A floating literal stands for an application of
-- <a>fromRational</a> to a value of type <a>Rational</a>, so such
-- literals have type <tt>(<a>Fractional</a> a) => a</tt>.
fromRational :: Rational -> a
-- | Trigonometric and hyperbolic functions and related functions.
class Fractional a => Floating a
pi :: a
exp :: a -> a
log :: a -> a
sqrt :: a -> a
(**) :: a -> a -> a
logBase :: a -> a -> a
sin :: a -> a
cos :: a -> a
tan :: a -> a
asin :: a -> a
acos :: a -> a
atan :: a -> a
sinh :: a -> a
cosh :: a -> a
tanh :: a -> a
asinh :: a -> a
acosh :: a -> a
atanh :: a -> a
-- | Extracting components of fractions.
class (Real a, Fractional a) => RealFrac a
-- | The function <a>properFraction</a> takes a real fractional number
-- <tt>x</tt> and returns a pair <tt>(n,f)</tt> such that <tt>x =
-- n+f</tt>, and:
--
-- <ul>
-- <li><tt>n</tt> is an integral number with the same sign as <tt>x</tt>;
-- and</li>
-- <li><tt>f</tt> is a fraction with the same type and sign as
-- <tt>x</tt>, and with absolute value less than <tt>1</tt>.</li>
-- </ul>
--
-- The default definitions of the <a>ceiling</a>, <a>floor</a>,
-- <a>truncate</a> and <a>round</a> functions are in terms of
-- <a>properFraction</a>.
properFraction :: Integral b => a -> (b, a)
-- | <tt><a>truncate</a> x</tt> returns the integer nearest <tt>x</tt>
-- between zero and <tt>x</tt>
truncate :: Integral b => a -> b
-- | <tt><a>round</a> x</tt> returns the nearest integer to <tt>x</tt>; the
-- even integer if <tt>x</tt> is equidistant between two integers
round :: Integral b => a -> b
-- | <tt><a>ceiling</a> x</tt> returns the least integer not less than
-- <tt>x</tt>
ceiling :: Integral b => a -> b
-- | <tt><a>floor</a> x</tt> returns the greatest integer not greater than
-- <tt>x</tt>
floor :: Integral b => a -> b
-- | Efficient, machine-independent access to the components of a
-- floating-point number.
class (RealFrac a, Floating a) => RealFloat a
-- | a constant function, returning the radix of the representation (often
-- <tt>2</tt>)
floatRadix :: a -> Integer
-- | a constant function, returning the number of digits of
-- <a>floatRadix</a> in the significand
floatDigits :: a -> Int
-- | a constant function, returning the lowest and highest values the
-- exponent may assume
floatRange :: a -> (Int, Int)
-- | The function <a>decodeFloat</a> applied to a real floating-point
-- number returns the significand expressed as an <a>Integer</a> and an
-- appropriately scaled exponent (an <a>Int</a>). If
-- <tt><a>decodeFloat</a> x</tt> yields <tt>(m,n)</tt>, then <tt>x</tt>
-- is equal in value to <tt>m*b^^n</tt>, where <tt>b</tt> is the
-- floating-point radix, and furthermore, either <tt>m</tt> and
-- <tt>n</tt> are both zero or else <tt>b^(d-1) <= <a>abs</a> m <
-- b^d</tt>, where <tt>d</tt> is the value of <tt><a>floatDigits</a>
-- x</tt>. In particular, <tt><a>decodeFloat</a> 0 = (0,0)</tt>. If the
-- type contains a negative zero, also <tt><a>decodeFloat</a> (-0.0) =
-- (0,0)</tt>. <i>The result of</i> <tt><a>decodeFloat</a> x</tt> <i>is
-- unspecified if either of</i> <tt><a>isNaN</a> x</tt> <i>or</i>
-- <tt><a>isInfinite</a> x</tt> <i>is</i> <a>True</a>.
decodeFloat :: a -> (Integer, Int)
-- | <a>encodeFloat</a> performs the inverse of <a>decodeFloat</a> in the
-- sense that for finite <tt>x</tt> with the exception of <tt>-0.0</tt>,
-- <tt><tt>uncurry</tt> <a>encodeFloat</a> (<a>decodeFloat</a> x) =
-- x</tt>. <tt><a>encodeFloat</a> m n</tt> is one of the two closest
-- representable floating-point numbers to <tt>m*b^^n</tt> (or
-- <tt>±Infinity</tt> if overflow occurs); usually the closer, but if
-- <tt>m</tt> contains too many bits, the result may be rounded in the
-- wrong direction.
encodeFloat :: Integer -> Int -> a
-- | <a>exponent</a> corresponds to the second component of
-- <a>decodeFloat</a>. <tt><a>exponent</a> 0 = 0</tt> and for finite
-- nonzero <tt>x</tt>, <tt><a>exponent</a> x = snd (<a>decodeFloat</a> x)
-- + <a>floatDigits</a> x</tt>. If <tt>x</tt> is a finite floating-point
-- number, it is equal in value to <tt><a>significand</a> x * b ^^
-- <a>exponent</a> x</tt>, where <tt>b</tt> is the floating-point radix.
-- The behaviour is unspecified on infinite or <tt>NaN</tt> values.
exponent :: a -> Int
-- | The first component of <a>decodeFloat</a>, scaled to lie in the open
-- interval (<tt>-1</tt>,<tt>1</tt>), either <tt>0.0</tt> or of absolute
-- value <tt>>= 1/b</tt>, where <tt>b</tt> is the floating-point
-- radix. The behaviour is unspecified on infinite or <tt>NaN</tt>
-- values.
significand :: a -> a
-- | multiplies a floating-point number by an integer power of the radix
scaleFloat :: Int -> a -> a
-- | <a>True</a> if the argument is an IEEE "not-a-number" (NaN) value
isNaN :: a -> Bool
-- | <a>True</a> if the argument is an IEEE infinity or negative infinity
isInfinite :: a -> Bool
-- | <a>True</a> if the argument is too small to be represented in
-- normalized format
isDenormalized :: a -> Bool
-- | <a>True</a> if the argument is an IEEE negative zero
isNegativeZero :: a -> Bool
-- | <a>True</a> if the argument is an IEEE floating point number
isIEEE :: a -> Bool
-- | a version of arctangent taking two real floating-point arguments. For
-- real floating <tt>x</tt> and <tt>y</tt>, <tt><a>atan2</a> y x</tt>
-- computes the angle (from the positive x-axis) of the vector from the
-- origin to the point <tt>(x,y)</tt>. <tt><a>atan2</a> y x</tt> returns
-- a value in the range [<tt>-pi</tt>, <tt>pi</tt>]. It follows the
-- Common Lisp semantics for the origin when signed zeroes are supported.
-- <tt><a>atan2</a> y 1</tt>, with <tt>y</tt> in a type that is
-- <a>RealFloat</a>, should return the same value as <tt><a>atan</a>
-- y</tt>. A default definition of <a>atan2</a> is provided, but
-- implementors can provide a more accurate implementation.
atan2 :: a -> a -> a
-- | The <a>Maybe</a> type encapsulates an optional value. A value of type
-- <tt><a>Maybe</a> a</tt> either contains a value of type <tt>a</tt>
-- (represented as <tt><a>Just</a> a</tt>), or it is empty (represented
-- as <a>Nothing</a>). Using <a>Maybe</a> is a good way to deal with
-- errors or exceptional cases without resorting to drastic measures such
-- as <a>error</a>.
--
-- The <a>Maybe</a> type is also a monad. It is a simple kind of error
-- monad, where all errors are represented by <a>Nothing</a>. A richer
-- error monad can be built using the <a>Either</a> type.
data Maybe a :: * -> *
Nothing :: Maybe a
Just :: a -> Maybe a
data Ordering :: *
LT :: Ordering
EQ :: Ordering
GT :: Ordering
data Bool :: *
False :: Bool
True :: Bool
-- | The character type <a>Char</a> is an enumeration whose values
-- represent Unicode (or equivalently ISO/IEC 10646) characters (see
-- <a>http://www.unicode.org/</a> for details). This set extends the ISO
-- 8859-1 (Latin-1) character set (the first 256 characters), which is
-- itself an extension of the ASCII character set (the first 128
-- characters). A character literal in Haskell has type <a>Char</a>.
--
-- To convert a <a>Char</a> to or from the corresponding <a>Int</a> value
-- defined by Unicode, use <a>toEnum</a> and <a>fromEnum</a> from the
-- <a>Enum</a> class respectively (or equivalently <tt>ord</tt> and
-- <tt>chr</tt>).
data Char :: *
-- | A value of type <tt><a>IO</a> a</tt> is a computation which, when
-- performed, does some I/O before returning a value of type <tt>a</tt>.
--
-- There is really only one way to "perform" an I/O action: bind it to
-- <tt>Main.main</tt> in your program. When your program is run, the I/O
-- will be performed. It isn't possible to perform I/O from an arbitrary
-- function, unless that function is itself in the <a>IO</a> monad and
-- called at some point, directly or indirectly, from <tt>Main.main</tt>.
--
-- <a>IO</a> is a monad, so <a>IO</a> actions can be combined using
-- either the do-notation or the <tt>>></tt> and <tt>>>=</tt>
-- operations from the <tt>Monad</tt> class.
data IO a :: * -> *
-- | The <a>Either</a> type represents values with two possibilities: a
-- value of type <tt><a>Either</a> a b</tt> is either <tt><a>Left</a>
-- a</tt> or <tt><a>Right</a> b</tt>.
--
-- The <a>Either</a> type is sometimes used to represent a value which is
-- either correct or an error; by convention, the <a>Left</a> constructor
-- is used to hold an error value and the <a>Right</a> constructor is
-- used to hold a correct value (mnemonic: "right" also means "correct").
--
-- <h4><b>Examples</b></h4>
--
-- The type <tt><a>Either</a> <a>String</a> <a>Int</a></tt> is the type
-- of values which can be either a <a>String</a> or an <a>Int</a>. The
-- <a>Left</a> constructor can be used only on <a>String</a>s, and the
-- <a>Right</a> constructor can be used only on <a>Int</a>s:
--
-- <pre>
-- >>> let s = Left "foo" :: Either String Int
--
-- >>> s
-- Left "foo"
--
-- >>> let n = Right 3 :: Either String Int
--
-- >>> n
-- Right 3
--
-- >>> :type s
-- s :: Either String Int
--
-- >>> :type n
-- n :: Either String Int
-- </pre>
--
-- The <a>fmap</a> from our <a>Functor</a> instance will ignore
-- <a>Left</a> values, but will apply the supplied function to values
-- contained in a <a>Right</a>:
--
-- <pre>
-- >>> let s = Left "foo" :: Either String Int
--
-- >>> let n = Right 3 :: Either String Int
--
-- >>> fmap (*2) s
-- Left "foo"
--
-- >>> fmap (*2) n
-- Right 6
-- </pre>
--
-- The <a>Monad</a> instance for <a>Either</a> allows us to chain
-- together multiple actions which may fail, and fail overall if any of
-- the individual steps failed. First we'll write a function that can
-- either parse an <a>Int</a> from a <a>Char</a>, or fail.
--
-- <pre>
-- >>> import Data.Char ( digitToInt, isDigit )
--
-- >>> :{
-- let parseEither :: Char -> Either String Int
-- parseEither c
-- | isDigit c = Right (digitToInt c)
-- | otherwise = Left "parse error"
--
-- >>> :}
-- </pre>
--
-- The following should work, since both <tt>'1'</tt> and <tt>'2'</tt>
-- can be parsed as <a>Int</a>s.
--
-- <pre>
-- >>> :{
-- let parseMultiple :: Either String Int
-- parseMultiple = do
-- x <- parseEither '1'
-- y <- parseEither '2'
-- return (x + y)
--
-- >>> :}
-- </pre>
--
-- <pre>
-- >>> parseMultiple
-- Right 3
-- </pre>
--
-- But the following should fail overall, since the first operation where
-- we attempt to parse <tt>'m'</tt> as an <a>Int</a> will fail:
--
-- <pre>
-- >>> :{
-- let parseMultiple :: Either String Int
-- parseMultiple = do
-- x <- parseEither 'm'
-- y <- parseEither '2'
-- return (x + y)
--
-- >>> :}
-- </pre>
--
-- <pre>
-- >>> parseMultiple
-- Left "parse error"
-- </pre>
data Either a b :: * -> * -> *
Left :: a -> Either a b
Right :: b -> Either a b
-- | A space-efficient representation of a <a>Word8</a> vector, supporting
-- many efficient operations.
--
-- A <a>ByteString</a> contains 8-bit bytes, or by using the operations
-- from <a>Data.ByteString.Char8</a> it can be interpreted as containing
-- 8-bit characters.
data ByteString :: *
type LByteString = ByteString
-- | A space efficient, packed, unboxed Unicode text type.
data Text :: *
type LText = Text
-- | A Map from keys <tt>k</tt> to values <tt>a</tt>.
data Map k a :: * -> * -> *
-- | A map from keys to values. A map cannot contain duplicate keys; each
-- key can map to at most one value.
data HashMap k v :: * -> * -> *
-- | A map of integers to values <tt>a</tt>.
data IntMap a :: * -> *
-- | A set of values <tt>a</tt>.
data Set a :: * -> *
-- | A set of values. A set cannot contain duplicate values.
data HashSet a :: * -> *
-- | A set of integers.
data IntSet :: *
-- | General-purpose finite sequences.
data Seq a :: * -> *
-- | Boxed vectors, supporting efficient slicing.
data Vector a :: * -> *
type UVector = Vector
class (Vector Vector a, MVector MVector a) => Unbox a
type SVector = Vector
-- | The member functions of this class facilitate writing values of
-- primitive types to raw memory (which may have been allocated with the
-- above mentioned routines) and reading values from blocks of raw
-- memory. The class, furthermore, includes support for computing the
-- storage requirements and alignment restrictions of storable types.
--
-- Memory addresses are represented as values of type <tt><a>Ptr</a>
-- a</tt>, for some <tt>a</tt> which is an instance of class
-- <a>Storable</a>. The type argument to <a>Ptr</a> helps provide some
-- valuable type safety in FFI code (you can't mix pointers of different
-- types without an explicit cast), while helping the Haskell type system
-- figure out which marshalling method is needed for a given pointer.
--
-- All marshalling between Haskell and a foreign language ultimately
-- boils down to translating Haskell data structures into the binary
-- representation of a corresponding data structure of the foreign
-- language and vice versa. To code this marshalling in Haskell, it is
-- necessary to manipulate primitive data types stored in unstructured
-- memory blocks. The class <a>Storable</a> facilitates this manipulation
-- on all types for which it is instantiated, which are the standard
-- basic types of Haskell, the fixed size <tt>Int</tt> types
-- (<a>Int8</a>, <a>Int16</a>, <a>Int32</a>, <a>Int64</a>), the fixed
-- size <tt>Word</tt> types (<a>Word8</a>, <a>Word16</a>, <a>Word32</a>,
-- <a>Word64</a>), <a>StablePtr</a>, all types from
-- <a>Foreign.C.Types</a>, as well as <a>Ptr</a>.
class Storable a
-- | The class of types that can be converted to a hash value.
--
-- Minimal implementation: <a>hashWithSalt</a>.
class Hashable a
-- | Return a hash value for the argument, using the given salt.
--
-- The general contract of <a>hashWithSalt</a> is:
--
-- <ul>
-- <li>If two values are equal according to the <a>==</a> method, then
-- applying the <a>hashWithSalt</a> method on each of the two values
-- <i>must</i> produce the same integer result if the same salt is used
-- in each case.</li>
-- <li>It is <i>not</i> required that if two values are unequal according
-- to the <a>==</a> method, then applying the <a>hashWithSalt</a> method
-- on each of the two values must produce distinct integer results.
-- However, the programmer should be aware that producing distinct
-- integer results for unequal values may improve the performance of
-- hashing-based data structures.</li>
-- <li>This method can be used to compute different hash values for the
-- same input by providing a different salt in each application of the
-- method. This implies that any instance that defines
-- <a>hashWithSalt</a> <i>must</i> make use of the salt in its
-- implementation.</li>
-- </ul>
hashWithSalt :: Int -> a -> Int
-- | Like <a>hashWithSalt</a>, but no salt is used. The default
-- implementation uses <a>hashWithSalt</a> with some default salt.
-- Instances might want to implement this method to provide a more
-- efficient implementation than the default implementation.
hash :: a -> Int
-- | A <a>Word</a> is an unsigned integral type, with the same size as
-- <a>Int</a>.
data Word :: *
-- | 8-bit unsigned integer type
data Word8 :: *
-- | 32-bit unsigned integer type
data Word32 :: *
-- | 64-bit unsigned integer type
data Word64 :: *
-- | A fixed-precision integer type with at least the range <tt>[-2^29 ..
-- 2^29-1]</tt>. The exact range for a given implementation can be
-- determined by using <a>minBound</a> and <a>maxBound</a> from the
-- <a>Bounded</a> class.
data Int :: *
-- | 32-bit signed integer type
data Int32 :: *
-- | 64-bit signed integer type
data Int64 :: *
-- | Invariant: <a>Jn#</a> and <a>Jp#</a> are used iff value doesn't fit in
-- <a>S#</a>
--
-- Useful properties resulting from the invariants:
--
-- <ul>
-- <li><pre>abs (<a>S#</a> _) <= abs (<a>Jp#</a> _)</pre></li>
-- <li><pre>abs (<a>S#</a> _) < abs (<a>Jn#</a> _)</pre></li>
-- </ul>
data Integer :: *
-- | Arbitrary-precision rational numbers, represented as a ratio of two
-- <a>Integer</a> values. A rational number may be constructed using the
-- <a>%</a> operator.
type Rational = Ratio Integer
-- | Single-precision floating point numbers. It is desirable that this
-- type be at least equal in range and precision to the IEEE
-- single-precision type.
data Float :: *
-- | Double-precision floating point numbers. It is desirable that this
-- type be at least equal in range and precision to the IEEE
-- double-precision type.
data Double :: *
-- | raise a number to a non-negative integral power
(^) :: (Num a, Integral b) => a -> b -> a
infixr 8 ^
-- | raise a number to an integral power
(^^) :: (Fractional a, Integral b) => a -> b -> a
infixr 8 ^^
-- | the same as <tt><a>flip</a> (<a>-</a>)</tt>.
--
-- Because <tt>-</tt> is treated specially in the Haskell grammar,
-- <tt>(-</tt> <i>e</i><tt>)</tt> is not a section, but an application of
-- prefix negation. However, <tt>(<a>subtract</a></tt>
-- <i>exp</i><tt>)</tt> is equivalent to the disallowed section.
subtract :: Num a => a -> a -> a
-- | general coercion from integral types
fromIntegral :: (Integral a, Num b) => a -> b
-- | general coercion to fractional types
realToFrac :: (Real a, Fractional b) => a -> b
-- | The class of monoids (types with an associative binary operation that
-- has an identity). Instances should satisfy the following laws:
--
-- <ul>
-- <li><pre>mappend mempty x = x</pre></li>
-- <li><pre>mappend x mempty = x</pre></li>
-- <li><pre>mappend x (mappend y z) = mappend (mappend x y) z</pre></li>
-- <li><pre>mconcat = <a>foldr</a> mappend mempty</pre></li>
-- </ul>
--
-- The method names refer to the monoid of lists under concatenation, but
-- there are many other instances.
--
-- Some types can be viewed as a monoid in more than one way, e.g. both
-- addition and multiplication on numbers. In such cases we often define
-- <tt>newtype</tt>s and make those instances of <a>Monoid</a>, e.g.
-- <tt>Sum</tt> and <tt>Product</tt>.
class Monoid a
-- | Identity of <a>mappend</a>
mempty :: a
-- | An associative operation
mappend :: a -> a -> a
-- | Fold a list using the monoid. For most types, the default definition
-- for <a>mconcat</a> will be used, but the function is included in the
-- class definition so that an optimized version can be provided for
-- specific types.
mconcat :: [a] -> a
-- | An infix synonym for <a>mappend</a>.
(<>) :: Monoid m => m -> m -> m
infixr 6 <>
-- | Data structures that can be folded.
--
-- For example, given a data type
--
-- <pre>
-- data Tree a = Empty | Leaf a | Node (Tree a) a (Tree a)
-- </pre>
--
-- a suitable instance would be
--
-- <pre>
-- instance Foldable Tree where
-- foldMap f Empty = mempty
-- foldMap f (Leaf x) = f x
-- foldMap f (Node l k r) = foldMap f l `mappend` f k `mappend` foldMap f r
-- </pre>
--
-- This is suitable even for abstract types, as the monoid is assumed to
-- satisfy the monoid laws. Alternatively, one could define
-- <tt>foldr</tt>:
--
-- <pre>
-- instance Foldable Tree where
-- foldr f z Empty = z
-- foldr f z (Leaf x) = f x z
-- foldr f z (Node l k r) = foldr f (f k (foldr f z r)) l
-- </pre>
--
-- <tt>Foldable</tt> instances are expected to satisfy the following
-- laws:
--
-- <pre>
-- foldr f z t = appEndo (foldMap (Endo . f) t ) z
-- </pre>
--
-- <pre>
-- foldl f z t = appEndo (getDual (foldMap (Dual . Endo . flip f) t)) z
-- </pre>
--
-- <pre>
-- fold = foldMap id
-- </pre>
--
-- <tt>sum</tt>, <tt>product</tt>, <tt>maximum</tt>, and <tt>minimum</tt>
-- should all be essentially equivalent to <tt>foldMap</tt> forms, such
-- as
--
-- <pre>
-- sum = getSum . foldMap Sum
-- </pre>
--
-- but may be less defined.
--
-- If the type is also a <a>Functor</a> instance, it should satisfy
--
-- <pre>
-- foldMap f = fold . fmap f
-- </pre>
--
-- which implies that
--
-- <pre>
-- foldMap f . fmap g = foldMap (f . g)
-- </pre>
class Foldable (t :: * -> *)
-- | The sum of a collection of actions, generalizing <a>concat</a>.
asum :: (Foldable t, Alternative f) => t (f a) -> f a
-- | Functors representing data structures that can be traversed from left
-- to right.
--
-- A definition of <a>traverse</a> must satisfy the following laws:
--
-- <ul>
-- <li><i><i>naturality</i></i> <tt>t . <a>traverse</a> f =
-- <a>traverse</a> (t . f)</tt> for every applicative transformation
-- <tt>t</tt></li>
-- <li><i><i>identity</i></i> <tt><a>traverse</a> Identity =
-- Identity</tt></li>
-- <li><i><i>composition</i></i> <tt><a>traverse</a> (Compose .
-- <a>fmap</a> g . f) = Compose . <a>fmap</a> (<a>traverse</a> g) .
-- <a>traverse</a> f</tt></li>
-- </ul>
--
-- A definition of <a>sequenceA</a> must satisfy the following laws:
--
-- <ul>
-- <li><i><i>naturality</i></i> <tt>t . <a>sequenceA</a> =
-- <a>sequenceA</a> . <a>fmap</a> t</tt> for every applicative
-- transformation <tt>t</tt></li>
-- <li><i><i>identity</i></i> <tt><a>sequenceA</a> . <a>fmap</a> Identity
-- = Identity</tt></li>
-- <li><i><i>composition</i></i> <tt><a>sequenceA</a> . <a>fmap</a>
-- Compose = Compose . <a>fmap</a> <a>sequenceA</a> .
-- <a>sequenceA</a></tt></li>
-- </ul>
--
-- where an <i>applicative transformation</i> is a function
--
-- <pre>
-- t :: (Applicative f, Applicative g) => f a -> g a
-- </pre>
--
-- preserving the <a>Applicative</a> operations, i.e.
--
-- <ul>
-- <li><pre>t (<a>pure</a> x) = <a>pure</a> x</pre></li>
-- <li><pre>t (x <a><*></a> y) = t x <a><*></a> t
-- y</pre></li>
-- </ul>
--
-- and the identity functor <tt>Identity</tt> and composition of functors
-- <tt>Compose</tt> are defined as
--
-- <pre>
-- newtype Identity a = Identity a
--
-- instance Functor Identity where
-- fmap f (Identity x) = Identity (f x)
--
-- instance Applicative Identity where
-- pure x = Identity x
-- Identity f <*> Identity x = Identity (f x)
--
-- newtype Compose f g a = Compose (f (g a))
--
-- instance (Functor f, Functor g) => Functor (Compose f g) where
-- fmap f (Compose x) = Compose (fmap (fmap f) x)
--
-- instance (Applicative f, Applicative g) => Applicative (Compose f g) where
-- pure x = Compose (pure (pure x))
-- Compose f <*> Compose x = Compose ((<*>) <$> f <*> x)
-- </pre>
--
-- (The naturality law is implied by parametricity.)
--
-- Instances are similar to <a>Functor</a>, e.g. given a data type
--
-- <pre>
-- data Tree a = Empty | Leaf a | Node (Tree a) a (Tree a)
-- </pre>
--
-- a suitable instance would be
--
-- <pre>
-- instance Traversable Tree where
-- traverse f Empty = pure Empty
-- traverse f (Leaf x) = Leaf <$> f x
-- traverse f (Node l k r) = Node <$> traverse f l <*> f k <*> traverse f r
-- </pre>
--
-- This is suitable even for abstract types, as the laws for
-- <a><*></a> imply a form of associativity.
--
-- The superclass instances should satisfy the following:
--
-- <ul>
-- <li>In the <a>Functor</a> instance, <a>fmap</a> should be equivalent
-- to traversal with the identity applicative functor
-- (<a>fmapDefault</a>).</li>
-- <li>In the <a>Foldable</a> instance, <a>foldMap</a> should be
-- equivalent to traversal with a constant applicative functor
-- (<a>foldMapDefault</a>).</li>
-- </ul>
class (Functor t, Foldable t) => Traversable (t :: * -> *)
-- | Send the first component of the input through the argument arrow, and
-- copy the rest unchanged to the output.
first :: Arrow a => forall b c d. a b c -> a (b, d) (c, d)
-- | A mirror image of <a>first</a>.
--
-- The default definition may be overridden with a more efficient version
-- if desired.
second :: Arrow a => forall b c d. a b c -> a (d, b) (d, c)
-- | Split the input between the two argument arrows and combine their
-- output. Note that this is in general not a functor.
--
-- The default definition may be overridden with a more efficient version
-- if desired.
(***) :: Arrow a => forall b c b' c'. a b c -> a b' c' -> a (b, b') (c, c')
-- | Fanout: send the input to both argument arrows and combine their
-- output.
--
-- The default definition may be overridden with a more efficient version
-- if desired.
(&&&) :: Arrow a => forall b c c'. a b c -> a b c' -> a b (c, c')
-- | Case analysis for the <a>Bool</a> type. <tt><a>bool</a> x y p</tt>
-- evaluates to <tt>x</tt> when <tt>p</tt> is <a>False</a>, and evaluates
-- to <tt>y</tt> when <tt>p</tt> is <a>True</a>.
--
-- This is equivalent to <tt>if p then y else x</tt>; that is, one can
-- think of it as an if-then-else construct with its arguments reordered.
--
-- <h4><b>Examples</b></h4>
--
-- Basic usage:
--
-- <pre>
-- >>> bool "foo" "bar" True
-- "bar"
--
-- >>> bool "foo" "bar" False
-- "foo"
-- </pre>
--
-- Confirm that <tt><a>bool</a> x y p</tt> and <tt>if p then y else
-- x</tt> are equivalent:
--
-- <pre>
-- >>> let p = True; x = "bar"; y = "foo"
--
-- >>> bool x y p == if p then y else x
-- True
--
-- >>> let p = False
--
-- >>> bool x y p == if p then y else x
-- True
-- </pre>
bool :: a -> a -> Bool -> a
-- | The <a>mapMaybe</a> function is a version of <a>map</a> which can
-- throw out elements. In particular, the functional argument returns
-- something of type <tt><a>Maybe</a> b</tt>. If this is <a>Nothing</a>,
-- no element is added on to the result list. If it is <tt><a>Just</a>
-- b</tt>, then <tt>b</tt> is included in the result list.
--
-- <h4><b>Examples</b></h4>
--
-- Using <tt><a>mapMaybe</a> f x</tt> is a shortcut for
-- <tt><a>catMaybes</a> $ <a>map</a> f x</tt> in most cases:
--
-- <pre>
-- >>> import Text.Read ( readMaybe )
--
-- >>> let readMaybeInt = readMaybe :: String -> Maybe Int
--
-- >>> mapMaybe readMaybeInt ["1", "Foo", "3"]
-- [1,3]
--
-- >>> catMaybes $ map readMaybeInt ["1", "Foo", "3"]
-- [1,3]
-- </pre>
--
-- If we map the <a>Just</a> constructor, the entire list should be
-- returned:
--
-- <pre>
-- >>> mapMaybe Just [1,2,3]
-- [1,2,3]
-- </pre>
mapMaybe :: (a -> Maybe b) -> [a] -> [b]
-- | The <a>catMaybes</a> function takes a list of <a>Maybe</a>s and
-- returns a list of all the <a>Just</a> values.
--
-- <h4><b>Examples</b></h4>
--
-- Basic usage:
--
-- <pre>
-- >>> catMaybes [Just 1, Nothing, Just 3]
-- [1,3]
-- </pre>
--
-- When constructing a list of <a>Maybe</a> values, <a>catMaybes</a> can
-- be used to return all of the "success" results (if the list is the
-- result of a <a>map</a>, then <a>mapMaybe</a> would be more
-- appropriate):
--
-- <pre>
-- >>> import Text.Read ( readMaybe )
--
-- >>> [readMaybe x :: Maybe Int | x <- ["1", "Foo", "3"] ]
-- [Just 1,Nothing,Just 3]
--
-- >>> catMaybes $ [readMaybe x :: Maybe Int | x <- ["1", "Foo", "3"] ]
-- [1,3]
-- </pre>
catMaybes :: [Maybe a] -> [a]
-- | The <a>fromMaybe</a> function takes a default value and and
-- <a>Maybe</a> value. If the <a>Maybe</a> is <a>Nothing</a>, it returns
-- the default values; otherwise, it returns the value contained in the
-- <a>Maybe</a>.
--
-- <h4><b>Examples</b></h4>
--
-- Basic usage:
--
-- <pre>
-- >>> fromMaybe "" (Just "Hello, World!")
-- "Hello, World!"
-- </pre>
--
-- <pre>
-- >>> fromMaybe "" Nothing
-- ""
-- </pre>
--
-- Read an integer from a string using <tt>readMaybe</tt>. If we fail to
-- parse an integer, we want to return <tt>0</tt> by default:
--
-- <pre>
-- >>> import Text.Read ( readMaybe )
--
-- >>> fromMaybe 0 (readMaybe "5")
-- 5
--
-- >>> fromMaybe 0 (readMaybe "")
-- 0
-- </pre>
fromMaybe :: a -> Maybe a -> a
-- | The <a>isJust</a> function returns <a>True</a> iff its argument is of
-- the form <tt>Just _</tt>.
--
-- <h4><b>Examples</b></h4>
--
-- Basic usage:
--
-- <pre>
-- >>> isJust (Just 3)
-- True
-- </pre>
--
-- <pre>
-- >>> isJust (Just ())
-- True
-- </pre>
--
-- <pre>
-- >>> isJust Nothing
-- False
-- </pre>
--
-- Only the outer constructor is taken into consideration:
--
-- <pre>
-- >>> isJust (Just Nothing)
-- True
-- </pre>
isJust :: Maybe a -> Bool
-- | The <a>isNothing</a> function returns <a>True</a> iff its argument is
-- <a>Nothing</a>.
--
-- <h4><b>Examples</b></h4>
--
-- Basic usage:
--
-- <pre>
-- >>> isNothing (Just 3)
-- False
-- </pre>
--
-- <pre>
-- >>> isNothing (Just ())
-- False
-- </pre>
--
-- <pre>
-- >>> isNothing Nothing
-- True
-- </pre>
--
-- Only the outer constructor is taken into consideration:
--
-- <pre>
-- >>> isNothing (Just Nothing)
-- False
-- </pre>
isNothing :: Maybe a -> Bool
-- | The <a>listToMaybe</a> function returns <a>Nothing</a> on an empty
-- list or <tt><a>Just</a> a</tt> where <tt>a</tt> is the first element
-- of the list.
--
-- <h4><b>Examples</b></h4>
--
-- Basic usage:
--
-- <pre>
-- >>> listToMaybe []
-- Nothing
-- </pre>
--
-- <pre>
-- >>> listToMaybe [9]
-- Just 9
-- </pre>
--
-- <pre>
-- >>> listToMaybe [1,2,3]
-- Just 1
-- </pre>
--
-- Composing <a>maybeToList</a> with <a>listToMaybe</a> should be the
-- identity on singleton/empty lists:
--
-- <pre>
-- >>> maybeToList $ listToMaybe [5]
-- [5]
--
-- >>> maybeToList $ listToMaybe []
-- []
-- </pre>
--
-- But not on lists with more than one element:
--
-- <pre>
-- >>> maybeToList $ listToMaybe [1,2,3]
-- [1]
-- </pre>
listToMaybe :: [a] -> Maybe a
-- | The <a>maybeToList</a> function returns an empty list when given
-- <a>Nothing</a> or a singleton list when not given <a>Nothing</a>.
--
-- <h4><b>Examples</b></h4>
--
-- Basic usage:
--
-- <pre>
-- >>> maybeToList (Just 7)
-- [7]
-- </pre>
--
-- <pre>
-- >>> maybeToList Nothing
-- []
-- </pre>
--
-- One can use <a>maybeToList</a> to avoid pattern matching when combined
-- with a function that (safely) works on lists:
--
-- <pre>
-- >>> import Text.Read ( readMaybe )
--
-- >>> sum $ maybeToList (readMaybe "3")
-- 3
--
-- >>> sum $ maybeToList (readMaybe "")
-- 0
-- </pre>
maybeToList :: Maybe a -> [a]
-- | Partitions a list of <a>Either</a> into two lists. All the <a>Left</a>
-- elements are extracted, in order, to the first component of the
-- output. Similarly the <a>Right</a> elements are extracted to the
-- second component of the output.
--
-- <h4><b>Examples</b></h4>
--
-- Basic usage:
--
-- <pre>
-- >>> let list = [ Left "foo", Right 3, Left "bar", Right 7, Left "baz" ]
--
-- >>> partitionEithers list
-- (["foo","bar","baz"],[3,7])
-- </pre>
--
-- The pair returned by <tt><a>partitionEithers</a> x</tt> should be the
-- same pair as <tt>(<a>lefts</a> x, <a>rights</a> x)</tt>:
--
-- <pre>
-- >>> let list = [ Left "foo", Right 3, Left "bar", Right 7, Left "baz" ]
--
-- >>> partitionEithers list == (lefts list, rights list)
-- True
-- </pre>
partitionEithers :: [Either a b] -> ([a], [b])
-- | Extracts from a list of <a>Either</a> all the <a>Left</a> elements.
-- All the <a>Left</a> elements are extracted in order.
--
-- <h4><b>Examples</b></h4>
--
-- Basic usage:
--
-- <pre>
-- >>> let list = [ Left "foo", Right 3, Left "bar", Right 7, Left "baz" ]
--
-- >>> lefts list
-- ["foo","bar","baz"]
-- </pre>
lefts :: [Either a b] -> [a]
-- | Extracts from a list of <a>Either</a> all the <a>Right</a> elements.
-- All the <a>Right</a> elements are extracted in order.
--
-- <h4><b>Examples</b></h4>
--
-- Basic usage:
--
-- <pre>
-- >>> let list = [ Left "foo", Right 3, Left "bar", Right 7, Left "baz" ]
--
-- >>> rights list
-- [3,7]
-- </pre>
rights :: [Either a b] -> [b]
-- | <tt>(*) `on` f = \x y -> f x * f y</tt>.
--
-- Typical usage: <tt><a>sortBy</a> (<tt>compare</tt> `on`
-- <tt>fst</tt>)</tt>.
--
-- Algebraic properties:
--
-- <ul>
-- <li><tt>(*) `on` <a>id</a> = (*)</tt> (if <tt>(*) ∉ {⊥, <a>const</a>
-- ⊥}</tt>)</li>
-- <li><pre>((*) `on` f) `on` g = (*) `on` (f . g)</pre></li>
-- <li><pre><a>flip</a> on f . <a>flip</a> on g = <a>flip</a> on (g .
-- f)</pre></li>
-- </ul>
on :: (b -> b -> c) -> (a -> b) -> a -> a -> c
infixl 0 `on`
-- | <pre>
-- comparing p x y = compare (p x) (p y)
-- </pre>
--
-- Useful combinator for use in conjunction with the <tt>xxxBy</tt>
-- family of functions from <a>Data.List</a>, for example:
--
-- <pre>
-- ... sortBy (comparing fst) ...
-- </pre>
comparing :: Ord a => (b -> a) -> b -> b -> Ordering
equating :: Eq a => (b -> a) -> b -> b -> Bool
-- | The <a>Down</a> type allows you to reverse sort order conveniently. A
-- value of type <tt><a>Down</a> a</tt> contains a value of type
-- <tt>a</tt> (represented as <tt><a>Down</a> a</tt>). If <tt>a</tt> has
-- an <tt><a>Ord</a></tt> instance associated with it then comparing two
-- values thus wrapped will give you the opposite of their normal sort
-- order. This is particularly useful when sorting in generalised list
-- comprehensions, as in: <tt>then sortWith by <a>Down</a> x</tt>
--
-- Provides <a>Show</a> and <a>Read</a> instances (<i>since:
-- 4.7.0.0</i>).
newtype Down a :: * -> *
Down :: a -> Down a
-- | A functor with application, providing operations to
--
-- <ul>
-- <li>embed pure expressions (<a>pure</a>), and</li>
-- <li>sequence computations and combine their results
-- (<a><*></a>).</li>
-- </ul>
--
-- A minimal complete definition must include implementations of these
-- functions satisfying the following laws:
--
-- <ul>
-- <li><i><i>identity</i></i> <pre><a>pure</a> <a>id</a> <a><*></a>
-- v = v</pre></li>
-- <li><i><i>composition</i></i> <pre><a>pure</a> (.) <a><*></a> u
-- <a><*></a> v <a><*></a> w = u <a><*></a> (v
-- <a><*></a> w)</pre></li>
-- <li><i><i>homomorphism</i></i> <pre><a>pure</a> f <a><*></a>
-- <a>pure</a> x = <a>pure</a> (f x)</pre></li>
-- <li><i><i>interchange</i></i> <pre>u <a><*></a> <a>pure</a> y =
-- <a>pure</a> (<a>$</a> y) <a><*></a> u</pre></li>
-- </ul>
--
-- The other methods have the following default definitions, which may be
-- overridden with equivalent specialized implementations:
--
-- <ul>
-- <li><pre>u <a>*></a> v = <a>pure</a> (<a>const</a> <a>id</a>)
-- <a><*></a> u <a><*></a> v</pre></li>
-- <li><pre>u <a><*</a> v = <a>pure</a> <a>const</a> <a><*></a>
-- u <a><*></a> v</pre></li>
-- </ul>
--
-- As a consequence of these laws, the <a>Functor</a> instance for
-- <tt>f</tt> will satisfy
--
-- <ul>
-- <li><pre><a>fmap</a> f x = <a>pure</a> f <a><*></a> x</pre></li>
-- </ul>
--
-- If <tt>f</tt> is also a <a>Monad</a>, it should satisfy
--
-- <ul>
-- <li><pre><a>pure</a> = <a>return</a></pre></li>
-- <li><pre>(<a><*></a>) = <a>ap</a></pre></li>
-- </ul>
--
-- (which implies that <a>pure</a> and <a><*></a> satisfy the
-- applicative functor laws).
class Functor f => Applicative (f :: * -> *)
-- | Lift a value.
pure :: a -> f a
-- | Sequential application.
(<*>) :: f (a -> b) -> f a -> f b
-- | Sequence actions, discarding the value of the first argument.
(*>) :: f a -> f b -> f b
-- | Sequence actions, discarding the value of the second argument.
(<*) :: f a -> f b -> f a
-- | An infix synonym for <a>fmap</a>.
--
-- The name of this operator is an allusion to <tt>$</tt>. Note the
-- similarities between their types:
--
-- <pre>
-- ($) :: (a -> b) -> a -> b
-- (<$>) :: Functor f => (a -> b) -> f a -> f b
-- </pre>
--
-- Whereas <tt>$</tt> is function application, <a><$></a> is
-- function application lifted over a <a>Functor</a>.
--
-- <h4><b>Examples</b></h4>
--
-- Convert from a <tt><tt>Maybe</tt> <tt>Int</tt></tt> to a
-- <tt><tt>Maybe</tt> <tt>String</tt></tt> using <tt>show</tt>:
--
-- <pre>
-- >>> show <$> Nothing
-- Nothing
--
-- >>> show <$> Just 3
-- Just "3"
-- </pre>
--
-- Convert from an <tt><tt>Either</tt> <tt>Int</tt> <tt>Int</tt></tt> to
-- an <tt><tt>Either</tt> <tt>Int</tt></tt> <tt>String</tt> using
-- <tt>show</tt>:
--
-- <pre>
-- >>> show <$> Left 17
-- Left 17
--
-- >>> show <$> Right 17
-- Right "17"
-- </pre>
--
-- Double each element of a list:
--
-- <pre>
-- >>> (*2) <$> [1,2,3]
-- [2,4,6]
-- </pre>
--
-- Apply <tt>even</tt> to the second element of a pair:
--
-- <pre>
-- >>> even <$> (2,2)
-- (2,True)
-- </pre>
(<$>) :: Functor f => (a -> b) -> f a -> f b
infixl 4 <$>
-- | An associative binary operation
(<|>) :: Alternative f => forall a. f a -> f a -> f a
-- | Left-to-right Kleisli composition of monads.
(>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c
infixr 1 >=>
-- | Lift a computation from the argument monad to the constructed monad.
lift :: MonadTrans t => forall (m :: * -> *) a. Monad m => m a -> t m a
-- | Monads in which <a>IO</a> computations may be embedded. Any monad
-- built by applying a sequence of monad transformers to the <a>IO</a>
-- monad will be an instance of this class.
--
-- Instances should satisfy the following laws, which state that
-- <a>liftIO</a> is a transformer of monads:
--
-- <ul>
-- <li><pre><a>liftIO</a> . <a>return</a> = <a>return</a></pre></li>
-- <li><pre><a>liftIO</a> (m >>= f) = <a>liftIO</a> m >>=
-- (<a>liftIO</a> . f)</pre></li>
-- </ul>
class Monad m => MonadIO (m :: * -> *)
-- | Lift a computation from the <a>IO</a> monad.
liftIO :: IO a -> m a
-- | Lift a computation from the <a>IO</a> monad.
liftIO :: MonadIO m => forall a. IO a -> m a
-- | Any type that you wish to throw or catch as an exception must be an
-- instance of the <tt>Exception</tt> class. The simplest case is a new
-- exception type directly below the root:
--
-- <pre>
-- data MyException = ThisException | ThatException
-- deriving (Show, Typeable)
--
-- instance Exception MyException
-- </pre>
--
-- The default method definitions in the <tt>Exception</tt> class do what
-- we need in this case. You can now throw and catch
-- <tt>ThisException</tt> and <tt>ThatException</tt> as exceptions:
--
-- <pre>
-- *Main> throw ThisException `catch` \e -> putStrLn ("Caught " ++ show (e :: MyException))
-- Caught ThisException
-- </pre>
--
-- In more complicated examples, you may wish to define a whole hierarchy
-- of exceptions:
--
-- <pre>
-- ---------------------------------------------------------------------
-- -- Make the root exception type for all the exceptions in a compiler
--
-- data SomeCompilerException = forall e . Exception e => SomeCompilerException e
-- deriving Typeable
--
-- instance Show SomeCompilerException where
-- show (SomeCompilerException e) = show e
--
-- instance Exception SomeCompilerException
--
-- compilerExceptionToException :: Exception e => e -> SomeException
-- compilerExceptionToException = toException . SomeCompilerException
--
-- compilerExceptionFromException :: Exception e => SomeException -> Maybe e
-- compilerExceptionFromException x = do
-- SomeCompilerException a <- fromException x
-- cast a
--
-- ---------------------------------------------------------------------
-- -- Make a subhierarchy for exceptions in the frontend of the compiler
--
-- data SomeFrontendException = forall e . Exception e => SomeFrontendException e
-- deriving Typeable
--
-- instance Show SomeFrontendException where
-- show (SomeFrontendException e) = show e
--
-- instance Exception SomeFrontendException where
-- toException = compilerExceptionToException
-- fromException = compilerExceptionFromException
--
-- frontendExceptionToException :: Exception e => e -> SomeException
-- frontendExceptionToException = toException . SomeFrontendException
--
-- frontendExceptionFromException :: Exception e => SomeException -> Maybe e
-- frontendExceptionFromException x = do
-- SomeFrontendException a <- fromException x
-- cast a
--
-- ---------------------------------------------------------------------
-- -- Make an exception type for a particular frontend compiler exception
--
-- data MismatchedParentheses = MismatchedParentheses
-- deriving (Typeable, Show)
--
-- instance Exception MismatchedParentheses where
-- toException = frontendExceptionToException
-- fromException = frontendExceptionFromException
-- </pre>
--
-- We can now catch a <tt>MismatchedParentheses</tt> exception as
-- <tt>MismatchedParentheses</tt>, <tt>SomeFrontendException</tt> or
-- <tt>SomeCompilerException</tt>, but not other types, e.g.
-- <tt>IOException</tt>:
--
-- <pre>
-- *Main> throw MismatchedParentheses <tt>catch</tt> e -> putStrLn ("Caught " ++ show (e :: MismatchedParentheses))
-- Caught MismatchedParentheses
-- *Main> throw MismatchedParentheses <tt>catch</tt> e -> putStrLn ("Caught " ++ show (e :: SomeFrontendException))
-- Caught MismatchedParentheses
-- *Main> throw MismatchedParentheses <tt>catch</tt> e -> putStrLn ("Caught " ++ show (e :: SomeCompilerException))
-- Caught MismatchedParentheses
-- *Main> throw MismatchedParentheses <tt>catch</tt> e -> putStrLn ("Caught " ++ show (e :: IOException))
-- *** Exception: MismatchedParentheses
-- </pre>
class (Typeable * e, Show e) => Exception e
toException :: e -> SomeException
fromException :: SomeException -> Maybe e
-- | Render this exception value in a human-friendly manner.
--
-- Default implementation: <tt><a>show</a></tt>.
displayException :: e -> String
-- | The class <a>Typeable</a> allows a concrete representation of a type
-- to be calculated.
class Typeable k (a :: k)
-- | The <tt>SomeException</tt> type is the root of the exception type
-- hierarchy. When an exception of type <tt>e</tt> is thrown, behind the
-- scenes it is encapsulated in a <tt>SomeException</tt>.
data SomeException :: *
-- | Exceptions that occur in the <tt>IO</tt> monad. An
-- <tt>IOException</tt> records a more specific error type, a descriptive
-- string and maybe the handle that was used when the error was flagged.
data IOException :: *
-- | Generalized version of <a>throwIO</a>.
throwIO :: (MonadBase IO m, Exception e) => e -> m a
-- | Generalized version of <a>try</a>.
--
-- Note, when the given computation throws an exception any monadic side
-- effects in <tt>m</tt> will be discarded.
try :: (MonadBaseControl IO m, Exception e) => m a -> m (Either e a)
-- | Generalized version of <a>tryJust</a>.
--
-- Note, when the given computation throws an exception any monadic side
-- effects in <tt>m</tt> will be discarded.
tryJust :: (MonadBaseControl IO m, Exception e) => (e -> Maybe b) -> m a -> m (Either b a)
-- | Generalized version of <a>catch</a>.
--
-- Note, when the given computation throws an exception any monadic side
-- effects in <tt>m</tt> will be discarded.
catch :: (MonadBaseControl IO m, Exception e) => m a -> (e -> m a) -> m a
-- | Generalized version of <a>catchJust</a>.
--
-- Note, when the given computation throws an exception any monadic side
-- effects in <tt>m</tt> will be discarded.
catchJust :: (MonadBaseControl IO m, Exception e) => (e -> Maybe b) -> m a -> (b -> m a) -> m a
-- | Generalized version of <a>handle</a>.
--
-- Note, when the given computation throws an exception any monadic side
-- effects in <tt>m</tt> will be discarded.
handle :: (MonadBaseControl IO m, Exception e) => (e -> m a) -> m a -> m a
-- | Generalized version of <a>handleJust</a>.
--
-- Note, when the given computation throws an exception any monadic side
-- effects in <tt>m</tt> will be discarded.
handleJust :: (MonadBaseControl IO m, Exception e) => (e -> Maybe b) -> (b -> m a) -> m a -> m a
-- | Generalized version of <a>bracket</a>.
--
-- Note:
--
-- <ul>
-- <li>When the "acquire" or "release" computations throw exceptions any
-- monadic side effects in <tt>m</tt> will be discarded.</li>
-- <li>When the "in-between" computation throws an exception any monadic
-- side effects in <tt>m</tt> produced by that computation will be
-- discarded but the side effects of the "acquire" or "release"
-- computations will be retained.</li>
-- <li>Also, any monadic side effects in <tt>m</tt> of the "release"
-- computation will be discarded; it is run only for its side effects in
-- <tt>IO</tt>.</li>
-- </ul>
--
-- Note that when your <tt>acquire</tt> and <tt>release</tt> computations
-- are of type <a>IO</a> it will be more efficient to write:
--
-- <pre>
-- <tt>liftBaseOp</tt> (<a>bracket</a> acquire release)
-- </pre>
bracket :: MonadBaseControl IO m => m a -> (a -> m b) -> (a -> m c) -> m c
-- | Generalized version of <a>bracket_</a>.
--
-- Note any monadic side effects in <tt>m</tt> of <i>both</i> the
-- "acquire" and "release" computations will be discarded. To keep the
-- monadic side effects of the "acquire" computation, use <a>bracket</a>
-- with constant functions instead.
--
-- Note that when your <tt>acquire</tt> and <tt>release</tt> computations
-- are of type <a>IO</a> it will be more efficient to write:
--
-- <pre>
-- <a>liftBaseOp_</a> (<a>bracket_</a> acquire release)
-- </pre>
bracket_ :: MonadBaseControl IO m => m a -> m b -> m c -> m c
-- | Generalized version of <a>bracketOnError</a>.
--
-- Note:
--
-- <ul>
-- <li>When the "acquire" or "release" computations throw exceptions any
-- monadic side effects in <tt>m</tt> will be discarded.</li>
-- <li>When the "in-between" computation throws an exception any monadic
-- side effects in <tt>m</tt> produced by that computation will be
-- discarded but the side effects of the "acquire" computation will be
-- retained.</li>
-- <li>Also, any monadic side effects in <tt>m</tt> of the "release"
-- computation will be discarded; it is run only for its side effects in
-- <tt>IO</tt>.</li>
-- </ul>
--
-- Note that when your <tt>acquire</tt> and <tt>release</tt> computations
-- are of type <a>IO</a> it will be more efficient to write:
--
-- <pre>
-- <tt>liftBaseOp</tt> (<a>bracketOnError</a> acquire release)
-- </pre>
bracketOnError :: MonadBaseControl IO m => m a -> (a -> m b) -> (a -> m c) -> m c
-- | Generalized version of <a>onException</a>.
--
-- Note, any monadic side effects in <tt>m</tt> of the "afterward"
-- computation will be discarded.
onException :: MonadBaseControl IO m => m a -> m b -> m a
-- | Generalized version of <a>finally</a>.
--
-- Note, any monadic side effects in <tt>m</tt> of the "afterward"
-- computation will be discarded.
finally :: MonadBaseControl IO m => m a -> m b -> m a
-- | Generalized version of <a>mask</a>.
mask :: MonadBaseControl IO m => ((forall a. m a -> m a) -> m b) -> m b
-- | Generalized version of <a>mask_</a>.
mask_ :: MonadBaseControl IO m => m a -> m a
-- | Generalized version of <a>uninterruptibleMask</a>.
uninterruptibleMask :: MonadBaseControl IO m => ((forall a. m a -> m a) -> m b) -> m b
-- | Generalized version of <a>uninterruptibleMask_</a>.
uninterruptibleMask_ :: MonadBaseControl IO m => m a -> m a
-- | File and directory names are values of type <a>String</a>, whose
-- precise meaning is operating system dependent. Files can be opened,
-- yielding a handle which can then be used to operate on the contents of
-- that file.
type FilePath = String
-- | Combine two paths with a path separator. If the second path starts
-- with a path separator or a drive letter, then it returns the second.
-- The intention is that <tt>readFile (dir <a></></a> file)</tt>
-- will access the same file as <tt>setCurrentDirectory dir; readFile
-- file</tt>.
--
-- <pre>
-- Posix: "/directory" </> "file.ext" == "/directory/file.ext"
-- Windows: "/directory" </> "file.ext" == "/directory\\file.ext"
-- "directory" </> "/file.ext" == "/file.ext"
-- Valid x => (takeDirectory x </> takeFileName x) `equalFilePath` x
-- </pre>
--
-- Combined:
--
-- <pre>
-- Posix: "/" </> "test" == "/test"
-- Posix: "home" </> "bob" == "home/bob"
-- Posix: "x:" </> "foo" == "x:/foo"
-- Windows: "C:\\foo" </> "bar" == "C:\\foo\\bar"
-- Windows: "home" </> "bob" == "home\\bob"
-- </pre>
--
-- Not combined:
--
-- <pre>
-- Posix: "home" </> "/bob" == "/bob"
-- Windows: "home" </> "C:\\bob" == "C:\\bob"
-- </pre>
--
-- Not combined (tricky):
--
-- On Windows, if a filepath starts with a single slash, it is relative
-- to the root of the current drive. In [1], this is (confusingly)
-- referred to as an absolute path. The current behavior of
-- <a></></a> is to never combine these forms.
--
-- <pre>
-- Windows: "home" </> "/bob" == "/bob"
-- Windows: "home" </> "\\bob" == "\\bob"
-- Windows: "C:\\home" </> "\\bob" == "\\bob"
-- </pre>
--
-- On Windows, from [1]: "If a file name begins with only a disk
-- designator but not the backslash after the colon, it is interpreted as
-- a relative path to the current directory on the drive with the
-- specified letter." The current behavior of <a></></a> is to
-- never combine these forms.
--
-- <pre>
-- Windows: "D:\\foo" </> "C:bar" == "C:bar"
-- Windows: "C:\\foo" </> "C:bar" == "C:bar"
-- </pre>
(</>) :: FilePath -> FilePath -> FilePath
infixr 5 </>
-- | Add an extension, even if there is already one there, equivalent to
-- <a>addExtension</a>.
--
-- <pre>
-- "/directory/path" <.> "ext" == "/directory/path.ext"
-- "/directory/path" <.> ".ext" == "/directory/path.ext"
-- </pre>
(<.>) :: FilePath -> String -> FilePath
infixr 7 <.>
-- | A <a>String</a> is a list of characters. String constants in Haskell
-- are values of type <a>String</a>.
type String = [Char]
-- | Like <a>hashWithSalt</a>, but no salt is used. The default
-- implementation uses <a>hashWithSalt</a> with some default salt.
-- Instances might want to implement this method to provide a more
-- efficient implementation than the default implementation.
hash :: Hashable a => a -> Int
-- | Return a hash value for the argument, using the given salt.
--
-- The general contract of <a>hashWithSalt</a> is:
--
-- <ul>
-- <li>If two values are equal according to the <a>==</a> method, then
-- applying the <a>hashWithSalt</a> method on each of the two values
-- <i>must</i> produce the same integer result if the same salt is used
-- in each case.</li>
-- <li>It is <i>not</i> required that if two values are unequal according
-- to the <a>==</a> method, then applying the <a>hashWithSalt</a> method
-- on each of the two values must produce distinct integer results.
-- However, the programmer should be aware that producing distinct
-- integer results for unequal values may improve the performance of
-- hashing-based data structures.</li>
-- <li>This method can be used to compute different hash values for the
-- same input by providing a different salt in each application of the
-- method. This implies that any instance that defines
-- <a>hashWithSalt</a> <i>must</i> make use of the salt in its
-- implementation.</li>
-- </ul>
hashWithSalt :: Hashable a => Int -> a -> Int
readArgs :: (MonadIO m, ArgumentTuple a) => m a
-- | BasicPrelude mostly re-exports several key libraries in their
-- entirety. The exception is Data.List, where various functions are
-- replaced by similar versions that are either generalized, operate on
-- Text, or are implemented strictly.
module BasicPrelude
-- | Data structures that can be folded.
--
-- For example, given a data type
--
-- <pre>
-- data Tree a = Empty | Leaf a | Node (Tree a) a (Tree a)
-- </pre>
--
-- a suitable instance would be
--
-- <pre>
-- instance Foldable Tree where
-- foldMap f Empty = mempty
-- foldMap f (Leaf x) = f x
-- foldMap f (Node l k r) = foldMap f l `mappend` f k `mappend` foldMap f r
-- </pre>
--
-- This is suitable even for abstract types, as the monoid is assumed to
-- satisfy the monoid laws. Alternatively, one could define
-- <tt>foldr</tt>:
--
-- <pre>
-- instance Foldable Tree where
-- foldr f z Empty = z
-- foldr f z (Leaf x) = f x z
-- foldr f z (Node l k r) = foldr f (f k (foldr f z r)) l
-- </pre>
--
-- <tt>Foldable</tt> instances are expected to satisfy the following
-- laws:
--
-- <pre>
-- foldr f z t = appEndo (foldMap (Endo . f) t ) z
-- </pre>
--
-- <pre>
-- foldl f z t = appEndo (getDual (foldMap (Dual . Endo . flip f) t)) z
-- </pre>
--
-- <pre>
-- fold = foldMap id
-- </pre>
--
-- <tt>sum</tt>, <tt>product</tt>, <tt>maximum</tt>, and <tt>minimum</tt>
-- should all be essentially equivalent to <tt>foldMap</tt> forms, such
-- as
--
-- <pre>
-- sum = getSum . foldMap Sum
-- </pre>
--
-- but may be less defined.
--
-- If the type is also a <a>Functor</a> instance, it should satisfy
--
-- <pre>
-- foldMap f = fold . fmap f
-- </pre>
--
-- which implies that
--
-- <pre>
-- foldMap f . fmap g = foldMap (f . g)
-- </pre>
class Foldable (t :: * -> *)
-- | Map each element of the structure to a monoid, and combine the
-- results.
foldMap :: Monoid m => (a -> m) -> t a -> m
-- | Right-associative fold of a structure.
--
-- In the case of lists, <a>foldr</a>, when applied to a binary operator,
-- a starting value (typically the right-identity of the operator), and a
-- list, reduces the list using the binary operator, from right to left:
--
-- <pre>
-- foldr f z [x1, x2, ..., xn] == x1 `f` (x2 `f` ... (xn `f` z)...)
-- </pre>
--
-- Note that, since the head of the resulting expression is produced by
-- an application of the operator to the first element of the list,
-- <a>foldr</a> can produce a terminating expression from an infinite
-- list.
--
-- For a general <a>Foldable</a> structure this should be semantically
-- identical to,
--
-- <pre>
-- foldr f z = <a>foldr</a> f z . <a>toList</a>
-- </pre>
foldr :: (a -> b -> b) -> b -> t a -> b
-- | Right-associative fold of a structure, but with strict application of
-- the operator.
foldr' :: (a -> b -> b) -> b -> t a -> b
-- | Left-associative fold of a structure.
--
-- In the case of lists, <a>foldl</a>, when applied to a binary operator,
-- a starting value (typically the left-identity of the operator), and a
-- list, reduces the list using the binary operator, from left to right:
--
-- <pre>
-- foldl f z [x1, x2, ..., xn] == (...((z `f` x1) `f` x2) `f`...) `f` xn
-- </pre>
--
-- Note that to produce the outermost application of the operator the
-- entire input list must be traversed. This means that <a>foldl'</a>
-- will diverge if given an infinite list.
--
-- Also note that if you want an efficient left-fold, you probably want
-- to use <a>foldl'</a> instead of <a>foldl</a>. The reason for this is
-- that latter does not force the "inner" results (e.g. <tt>z <tt>f</tt>
-- x1</tt> in the above example) before applying them to the operator
-- (e.g. to <tt>(<tt>f</tt> x2)</tt>). This results in a thunk chain
-- <tt>O(n)</tt> elements long, which then must be evaluated from the
-- outside-in.
--
-- For a general <a>Foldable</a> structure this should be semantically
-- identical to,
--
-- <pre>
-- foldl f z = <a>foldl</a> f z . <a>toList</a>
-- </pre>
foldl :: (b -> a -> b) -> b -> t a -> b
-- | Left-associative fold of a structure but with strict application of
-- the operator.
--
-- This ensures that each step of the fold is forced to weak head normal
-- form before being applied, avoiding the collection of thunks that
-- would otherwise occur. This is often what you want to strictly reduce
-- a finite list to a single, monolithic result (e.g. <a>length</a>).
--
-- For a general <a>Foldable</a> structure this should be semantically
-- identical to,
--
-- <pre>
-- foldl f z = <a>foldl'</a> f z . <a>toList</a>
-- </pre>
foldl' :: (b -> a -> b) -> b -> t a -> b
-- | A variant of <a>foldr</a> that has no base case, and thus may only be
-- applied to non-empty structures.
--
-- <pre>
-- <a>foldr1</a> f = <a>foldr1</a> f . <a>toList</a>
-- </pre>
foldr1 :: (a -> a -> a) -> t a -> a
-- | A variant of <a>foldl</a> that has no base case, and thus may only be
-- applied to non-empty structures.
--
-- <pre>
-- <a>foldl1</a> f = <a>foldl1</a> f . <a>toList</a>
-- </pre>
foldl1 :: (a -> a -> a) -> t a -> a
-- | Test whether the structure is empty. The default implementation is
-- optimized for structures that are similar to cons-lists, because there
-- is no general way to do better.
null :: t a -> Bool
-- | Returns the size/length of a finite structure as an <a>Int</a>. The
-- default implementation is optimized for structures that are similar to
-- cons-lists, because there is no general way to do better.
length :: t a -> Int
-- | Does the element occur in the structure?
elem :: Eq a => a -> t a -> Bool
-- | The largest element of a non-empty structure.
maximum :: Ord a => t a -> a
-- | The least element of a non-empty structure.
minimum :: Ord a => t a -> a
-- | Does the element occur in the structure?
elem :: Foldable t => forall a. Eq a => a -> t a -> Bool
-- | The largest element of a non-empty structure.
maximum :: Foldable t => forall a. Ord a => t a -> a
-- | The least element of a non-empty structure.
minimum :: Foldable t => forall a. Ord a => t a -> a
-- | Functors representing data structures that can be traversed from left
-- to right.
--
-- A definition of <a>traverse</a> must satisfy the following laws:
--
-- <ul>
-- <li><i><i>naturality</i></i> <tt>t . <a>traverse</a> f =
-- <a>traverse</a> (t . f)</tt> for every applicative transformation
-- <tt>t</tt></li>
-- <li><i><i>identity</i></i> <tt><a>traverse</a> Identity =
-- Identity</tt></li>
-- <li><i><i>composition</i></i> <tt><a>traverse</a> (Compose .
-- <a>fmap</a> g . f) = Compose . <a>fmap</a> (<a>traverse</a> g) .
-- <a>traverse</a> f</tt></li>
-- </ul>
--
-- A definition of <a>sequenceA</a> must satisfy the following laws:
--
-- <ul>
-- <li><i><i>naturality</i></i> <tt>t . <a>sequenceA</a> =
-- <a>sequenceA</a> . <a>fmap</a> t</tt> for every applicative
-- transformation <tt>t</tt></li>
-- <li><i><i>identity</i></i> <tt><a>sequenceA</a> . <a>fmap</a> Identity
-- = Identity</tt></li>
-- <li><i><i>composition</i></i> <tt><a>sequenceA</a> . <a>fmap</a>
-- Compose = Compose . <a>fmap</a> <a>sequenceA</a> .
-- <a>sequenceA</a></tt></li>
-- </ul>
--
-- where an <i>applicative transformation</i> is a function
--
-- <pre>
-- t :: (Applicative f, Applicative g) => f a -> g a
-- </pre>
--
-- preserving the <a>Applicative</a> operations, i.e.
--
-- <ul>
-- <li><pre>t (<a>pure</a> x) = <a>pure</a> x</pre></li>
-- <li><pre>t (x <a><*></a> y) = t x <a><*></a> t
-- y</pre></li>
-- </ul>
--
-- and the identity functor <tt>Identity</tt> and composition of functors
-- <tt>Compose</tt> are defined as
--
-- <pre>
-- newtype Identity a = Identity a
--
-- instance Functor Identity where
-- fmap f (Identity x) = Identity (f x)
--
-- instance Applicative Identity where
-- pure x = Identity x
-- Identity f <*> Identity x = Identity (f x)
--
-- newtype Compose f g a = Compose (f (g a))
--
-- instance (Functor f, Functor g) => Functor (Compose f g) where
-- fmap f (Compose x) = Compose (fmap (fmap f) x)
--
-- instance (Applicative f, Applicative g) => Applicative (Compose f g) where
-- pure x = Compose (pure (pure x))
-- Compose f <*> Compose x = Compose ((<*>) <$> f <*> x)
-- </pre>
--
-- (The naturality law is implied by parametricity.)
--
-- Instances are similar to <a>Functor</a>, e.g. given a data type
--
-- <pre>
-- data Tree a = Empty | Leaf a | Node (Tree a) a (Tree a)
-- </pre>
--
-- a suitable instance would be
--
-- <pre>
-- instance Traversable Tree where
-- traverse f Empty = pure Empty
-- traverse f (Leaf x) = Leaf <$> f x
-- traverse f (Node l k r) = Node <$> traverse f l <*> f k <*> traverse f r
-- </pre>
--
-- This is suitable even for abstract types, as the laws for
-- <a><*></a> imply a form of associativity.
--
-- The superclass instances should satisfy the following:
--
-- <ul>
-- <li>In the <a>Functor</a> instance, <a>fmap</a> should be equivalent
-- to traversal with the identity applicative functor
-- (<a>fmapDefault</a>).</li>
-- <li>In the <a>Foldable</a> instance, <a>foldMap</a> should be
-- equivalent to traversal with a constant applicative functor
-- (<a>foldMapDefault</a>).</li>
-- </ul>
class (Functor t, Foldable t) => Traversable (t :: * -> *)
-- | Map each element of a structure to an action, evaluate these actions
-- from left to right, and collect the results. For a version that
-- ignores the results see <a>traverse_</a>.
traverse :: Applicative f => (a -> f b) -> t a -> f (t b)
-- | Evaluate each action in the structure from left to right, and and
-- collect the results. For a version that ignores the results see
-- <a>sequenceA_</a>.
sequenceA :: Applicative f => t (f a) -> f (t a)
-- | Map each element of a structure to a monadic action, evaluate these
-- actions from left to right, and collect the results. For a version
-- that ignores the results see <a>mapM_</a>.
mapM :: Monad m => (a -> m b) -> t a -> m (t b)
-- | Evaluate each monadic action in the structure from left to right, and
-- collect the results. For a version that ignores the results see
-- <a>sequence_</a>.
sequence :: Monad m => t (m a) -> m (t a)
-- | <pre>
-- map = fmap
-- </pre>
map :: (Functor f) => (a -> b) -> f a -> f b
-- | <pre>
-- empty = mempty
-- </pre>
-- | <i>Deprecated: Use mempty</i>
empty :: Monoid w => w
-- | <pre>
-- (++) = mappend
-- </pre>
(++) :: Monoid w => w -> w -> w
infixr 5 ++
-- | <pre>
-- concat = mconcat
-- </pre>
concat :: Monoid w => [w] -> w
-- | <pre>
-- intercalate = mconcat .: intersperse
-- </pre>
intercalate :: Monoid w => w -> [w] -> w
-- | Compute the sum of a finite list of numbers.
sum :: (Foldable f, Num a) => f a -> a
-- | Compute the product of a finite list of numbers.
product :: (Foldable f, Num a) => f a -> a
-- | Convert a value to readable Text
tshow :: Show a => a -> Text
-- | Convert a value to readable IsString
--
-- Since 0.3.12
fromShow :: (Show a, IsString b) => a -> b
-- | Parse Text to a value
read :: Read a => Text -> a
-- | The readIO function is similar to read except that it signals parse
-- failure to the IO monad instead of terminating the program.
readIO :: Read a => Text -> IO a
-- | Read a file and return the contents of the file as Text. The entire
-- file is read strictly.
readFile :: FilePath -> IO Text
-- | Write Text to a file. The file is truncated to zero length before
-- writing begins.
writeFile :: FilePath -> Text -> IO ()
-- | Write Text to the end of a file.
appendFile :: FilePath -> Text -> IO ()
-- | <i>O(n)</i> Breaks a <a>Text</a> up into a list of <a>Text</a>s at
-- newline <a>Char</a>s. The resulting strings do not contain newlines.
lines :: Text -> [Text]
-- | <i>O(n)</i> Breaks a <a>Text</a> up into a list of words, delimited by
-- <a>Char</a>s representing white space.
words :: Text -> [Text]
-- | <i>O(n)</i> Joins lines, after appending a terminating newline to
-- each.
unlines :: [Text] -> Text
-- | <i>O(n)</i> Joins words using single space characters.
unwords :: [Text] -> Text
textToString :: Text -> String
ltextToString :: LText -> String
-- | This function assumes file paths are encoded in UTF8. If it cannot
-- decode the <a>FilePath</a>, the result is just an approximation.
--
-- Since 0.3.13
-- | <i>Deprecated: Use Data.Text.pack</i>
fpToText :: FilePath -> Text
-- | Since 0.3.13
-- | <i>Deprecated: Use Data.Text.unpack</i>
fpFromText :: Text -> FilePath
-- | Since 0.3.13
-- | <i>Deprecated: Use id</i>
fpToString :: FilePath -> String
-- | Encode text using UTF-8 encoding.
encodeUtf8 :: Text -> ByteString
-- | Note that this is <i>not</i> the standard
-- <tt>Data.Text.Encoding.decodeUtf8</tt>. That function will throw
-- impure exceptions on any decoding errors. This function instead uses
-- <tt>decodeLenient</tt>.
decodeUtf8 :: ByteString -> Text
-- | Read a single line of user input from <a>stdin</a>.
getLine :: IO Text
-- | Lazily read all user input on <a>stdin</a> as a single string.
getContents :: IO Text
-- | The <a>interact</a> function takes a function of type <tt>Text ->
-- Text</tt> as its argument. The entire input from the standard input
-- device is passed (lazily) to this function as its argument, and the
-- resulting string is output on the standard output device.
interact :: (Text -> Text) -> IO ()
-- | <tt><a>gcd</a> x y</tt> is the non-negative factor of both <tt>x</tt>
-- and <tt>y</tt> of which every common factor of <tt>x</tt> and
-- <tt>y</tt> is also a factor; for example <tt><a>gcd</a> 4 2 = 2</tt>,
-- <tt><a>gcd</a> (-4) 6 = 2</tt>, <tt><a>gcd</a> 0 4</tt> = <tt>4</tt>.
-- <tt><a>gcd</a> 0 0</tt> = <tt>0</tt>. (That is, the common divisor
-- that is "greatest" in the divisibility preordering.)
--
-- Note: Since for signed fixed-width integer types, <tt><a>abs</a>
-- <a>minBound</a> < 0</tt>, the result may be negative if one of the
-- arguments is <tt><a>minBound</a></tt> (and necessarily is if the other
-- is <tt>0</tt> or <tt><a>minBound</a></tt>) for such types.
gcd :: Integral a => a -> a -> a
-- | <tt><a>lcm</a> x y</tt> is the smallest positive integer that both
-- <tt>x</tt> and <tt>y</tt> divide.
lcm :: Integral a => a -> a -> a
-- | Conversion of values to readable <a>String</a>s.
--
-- Derived instances of <a>Show</a> have the following properties, which
-- are compatible with derived instances of <a>Read</a>:
--
-- <ul>
-- <li>The result of <a>show</a> is a syntactically correct Haskell
-- expression containing only constants, given the fixity declarations in
-- force at the point where the type is declared. It contains only the
-- constructor names defined in the data type, parentheses, and spaces.
-- When labelled constructor fields are used, braces, commas, field
-- names, and equal signs are also used.</li>
-- <li>If the constructor is defined to be an infix operator, then
-- <a>showsPrec</a> will produce infix applications of the
-- constructor.</li>
-- <li>the representation will be enclosed in parentheses if the
-- precedence of the top-level constructor in <tt>x</tt> is less than
-- <tt>d</tt> (associativity is ignored). Thus, if <tt>d</tt> is
-- <tt>0</tt> then the result is never surrounded in parentheses; if
-- <tt>d</tt> is <tt>11</tt> it is always surrounded in parentheses,
-- unless it is an atomic expression.</li>
-- <li>If the constructor is defined using record syntax, then
-- <a>show</a> will produce the record-syntax form, with the fields given
-- in the same order as the original declaration.</li>
-- </ul>
--
-- For example, given the declarations
--
-- <pre>
-- infixr 5 :^:
-- data Tree a = Leaf a | Tree a :^: Tree a
-- </pre>
--
-- the derived instance of <a>Show</a> is equivalent to
--
-- <pre>
-- instance (Show a) => Show (Tree a) where
--
-- showsPrec d (Leaf m) = showParen (d > app_prec) $
-- showString "Leaf " . showsPrec (app_prec+1) m
-- where app_prec = 10
--
-- showsPrec d (u :^: v) = showParen (d > up_prec) $
-- showsPrec (up_prec+1) u .
-- showString " :^: " .
-- showsPrec (up_prec+1) v
-- where up_prec = 5
-- </pre>
--
-- Note that right-associativity of <tt>:^:</tt> is ignored. For example,
--
-- <ul>
-- <li><tt><a>show</a> (Leaf 1 :^: Leaf 2 :^: Leaf 3)</tt> produces the
-- string <tt>"Leaf 1 :^: (Leaf 2 :^: Leaf 3)"</tt>.</li>
-- </ul>
class Show a
-- | Convert a value to a readable <a>String</a>.
--
-- <a>showsPrec</a> should satisfy the law
--
-- <pre>
-- showsPrec d x r ++ s == showsPrec d x (r ++ s)
-- </pre>
--
-- Derived instances of <a>Read</a> and <a>Show</a> satisfy the
-- following:
--
-- <ul>
-- <li><tt>(x,"")</tt> is an element of <tt>(<a>readsPrec</a> d
-- (<a>showsPrec</a> d x ""))</tt>.</li>
-- </ul>
--
-- That is, <a>readsPrec</a> parses the string produced by
-- <a>showsPrec</a>, and delivers the value that <a>showsPrec</a> started
-- with.
showsPrec :: Int -> a -> ShowS
-- | A specialised variant of <a>showsPrec</a>, using precedence context
-- zero, and returning an ordinary <a>String</a>.
show :: a -> String
-- | The method <a>showList</a> is provided to allow the programmer to give
-- a specialised way of showing lists of values. For example, this is
-- used by the predefined <a>Show</a> instance of the <a>Char</a> type,
-- where values of type <a>String</a> should be shown in double quotes,
-- rather than between square brackets.
showList :: [a] -> ShowS
-- | The <tt>shows</tt> functions return a function that prepends the
-- output <a>String</a> to an existing <a>String</a>. This allows
-- constant-time concatenation of results using function composition.
type ShowS = String -> String
-- | equivalent to <a>showsPrec</a> with a precedence of 0.
shows :: Show a => a -> ShowS
-- | utility function converting a <a>Char</a> to a show function that
-- simply prepends the character unchanged.
showChar :: Char -> ShowS
-- | utility function converting a <a>String</a> to a show function that
-- simply prepends the string unchanged.
showString :: String -> ShowS
-- | utility function that surrounds the inner show function with
-- parentheses when the <a>Bool</a> parameter is <a>True</a>.
showParen :: Bool -> ShowS -> ShowS
-- | A parser for a type <tt>a</tt>, represented as a function that takes a
-- <a>String</a> and returns a list of possible parses as
-- <tt>(a,<a>String</a>)</tt> pairs.
--
-- Note that this kind of backtracking parser is very inefficient;
-- reading a large structure may be quite slow (cf <a>ReadP</a>).
type ReadS a = String -> [(a, String)]
-- | attempts to parse a value from the front of the string, returning a
-- list of (parsed value, remaining string) pairs. If there is no
-- successful parse, the returned list is empty.
--
-- Derived instances of <a>Read</a> and <a>Show</a> satisfy the
-- following:
--
-- <ul>
-- <li><tt>(x,"")</tt> is an element of <tt>(<a>readsPrec</a> d
-- (<a>showsPrec</a> d x ""))</tt>.</li>
-- </ul>
--
-- That is, <a>readsPrec</a> parses the string produced by
-- <a>showsPrec</a>, and delivers the value that <a>showsPrec</a> started
-- with.
readsPrec :: Read a => Int -> ReadS a
-- | The method <a>readList</a> is provided to allow the programmer to give
-- a specialised way of parsing lists of values. For example, this is
-- used by the predefined <a>Read</a> instance of the <a>Char</a> type,
-- where values of type <a>String</a> should be are expected to use
-- double quotes, rather than square brackets.
readList :: Read a => ReadS [a]
-- | equivalent to <a>readsPrec</a> with a precedence of 0.
reads :: Read a => ReadS a
-- | <tt><a>readParen</a> <a>True</a> p</tt> parses what <tt>p</tt> parses,
-- but surrounded with parentheses.
--
-- <tt><a>readParen</a> <a>False</a> p</tt> parses what <tt>p</tt>
-- parses, but optionally surrounded with parentheses.
readParen :: Bool -> ReadS a -> ReadS a
-- | The <a>lex</a> function reads a single lexeme from the input,
-- discarding initial white space, and returning the characters that
-- constitute the lexeme. If the input string contains only white space,
-- <a>lex</a> returns a single successful `lexeme' consisting of the
-- empty string. (Thus <tt><a>lex</a> "" = [("","")]</tt>.) If there is
-- no legal lexeme at the beginning of the input string, <a>lex</a> fails
-- (i.e. returns <tt>[]</tt>).
--
-- This lexer is not completely faithful to the Haskell lexical syntax in
-- the following respects:
--
-- <ul>
-- <li>Qualified names are not handled properly</li>
-- <li>Octal and hexadecimal numerics are not recognized as a single
-- token</li>
-- <li>Comments are not treated properly</li>
-- </ul>
lex :: ReadS String
readMay :: Read a => Text -> Maybe a
-- | Write a character to the standard output device (same as
-- <a>hPutChar</a> <a>stdout</a>).
putChar :: Char -> IO ()
-- | Read a character from the standard input device (same as
-- <a>hGetChar</a> <a>stdin</a>).
getChar :: IO Char
-- | The <a>readLn</a> function combines <a>getLine</a> and <a>readIO</a>.
readLn :: Read a => IO a
|