constrained-categories (empty) → 0.1.0.0
raw patch · 12 files changed
+2364/−0 lines, 12 filesdep +basedep +taggeddep +voidsetup-changed
Dependencies added: base, tagged, void
Files
- COPYING +674/−0
- Control/Applicative/Constrained.hs +106/−0
- Control/Arrow/Constrained.hs +424/−0
- Control/Category/Constrained.hs +402/−0
- Control/Category/Constrained/Prelude.hs +32/−0
- Control/Category/Hask.hs +36/−0
- Control/Functor/Constrained.hs +95/−0
- Control/Monad/Constrained.hs +274/−0
- Data/Foldable/Constrained.hs +166/−0
- Data/Traversable/Constrained.hs +91/−0
- Setup.hs +6/−0
- constrained-categories.cabal +58/−0
+ COPYING view
@@ -0,0 +1,674 @@+ GNU GENERAL PUBLIC LICENSE+ Version 3, 29 June 2007++ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>+ Everyone is permitted to copy and distribute verbatim copies+ of this license document, but changing it is not allowed.++ Preamble++ The GNU General Public License is a free, copyleft license for+software and other kinds of works.++ The licenses for most software and other practical works are designed+to take away your freedom to share and change the works. By contrast,+the GNU General Public License is intended to guarantee your freedom to+share and change all versions of a program--to make sure it remains free+software for all its users. We, the Free Software Foundation, use the+GNU General Public License for most of our software; it applies also to+any other work released this way by its authors. You can apply it to+your programs, too.++ When we speak of free software, we are referring to freedom, not+price. Our General Public Licenses are designed to make sure that you+have the freedom to distribute copies of free software (and charge for+them if you wish), that you receive source code or can get it if you+want it, that you can change the software or use pieces of it in new+free programs, and that you know you can do these things.++ To protect your rights, we need to prevent others from denying you+these rights or asking you to surrender the rights. Therefore, you have+certain responsibilities if you distribute copies of the software, or if+you modify it: responsibilities to respect the freedom of others.++ For example, if you distribute copies of such a program, whether+gratis or for a fee, you must pass on to the recipients the same+freedoms that you received. You must make sure that they, too, receive+or can get the source code. And you must show them these terms so they+know their rights.++ Developers that use the GNU GPL protect your rights with two steps:+(1) assert copyright on the software, and (2) offer you this License+giving you legal permission to copy, distribute and/or modify it.++ For the developers' and authors' protection, the GPL clearly explains+that there is no warranty for this free software. For both users' and+authors' sake, the GPL requires that modified versions be marked as+changed, so that their problems will not be attributed erroneously to+authors of previous versions.++ Some devices are designed to deny users access to install or run+modified versions of the software inside them, although the manufacturer+can do so. This is fundamentally incompatible with the aim of+protecting users' freedom to change the software. The systematic+pattern of such abuse occurs in the area of products for individuals to+use, which is precisely where it is most unacceptable. Therefore, we+have designed this version of the GPL to prohibit the practice for those+products. If such problems arise substantially in other domains, we+stand ready to extend this provision to those domains in future versions+of the GPL, as needed to protect the freedom of users.++ Finally, every program is threatened constantly by software patents.+States should not allow patents to restrict development and use of+software on general-purpose computers, but in those that do, we wish to+avoid the special danger that patents applied to a free program could+make it effectively proprietary. To prevent this, the GPL assures that+patents cannot be used to render the program non-free.++ The precise terms and conditions for copying, distribution and+modification follow.++ TERMS AND CONDITIONS++ 0. Definitions.++ "This License" refers to version 3 of the GNU General Public License.++ "Copyright" also means copyright-like laws that apply to other kinds of+works, such as semiconductor masks.++ "The Program" refers to any copyrightable work licensed under this+License. Each licensee is addressed as "you". "Licensees" and+"recipients" may be individuals or organizations.++ To "modify" a work means to copy from or adapt all or part of the work+in a fashion requiring copyright permission, other than the making of an+exact copy. The resulting work is called a "modified version" of the+earlier work or a work "based on" the earlier work.++ A "covered work" means either the unmodified Program or a work based+on the Program.++ To "propagate" a work means to do anything with it that, without+permission, would make you directly or secondarily liable for+infringement under applicable copyright law, except executing it on a+computer or modifying a private copy. Propagation includes copying,+distribution (with or without modification), making available to the+public, and in some countries other activities as well.++ To "convey" a work means any kind of propagation that enables other+parties to make or receive copies. Mere interaction with a user through+a computer network, with no transfer of a copy, is not conveying.++ An interactive user interface displays "Appropriate Legal Notices"+to the extent that it includes a convenient and prominently visible+feature that (1) displays an appropriate copyright notice, and (2)+tells the user that there is no warranty for the work (except to the+extent that warranties are provided), that licensees may convey the+work under this License, and how to view a copy of this License. If+the interface presents a list of user commands or options, such as a+menu, a prominent item in the list meets this criterion.++ 1. Source Code.++ The "source code" for a work means the preferred form of the work+for making modifications to it. "Object code" means any non-source+form of a work.++ A "Standard Interface" means an interface that either is an official+standard defined by a recognized standards body, or, in the case of+interfaces specified for a particular programming language, one that+is widely used among developers working in that language.++ The "System Libraries" of an executable work include anything, other+than the work as a whole, that (a) is included in the normal form of+packaging a Major Component, but which is not part of that Major+Component, and (b) serves only to enable use of the work with that+Major Component, or to implement a Standard Interface for which an+implementation is available to the public in source code form. A+"Major Component", in this context, means a major essential component+(kernel, window system, and so on) of the specific operating system+(if any) on which the executable work runs, or a compiler used to+produce the work, or an object code interpreter used to run it.++ The "Corresponding Source" for a work in object code form means all+the source code needed to generate, install, and (for an executable+work) run the object code and to modify the work, including scripts to+control those activities. However, it does not include the work's+System Libraries, or general-purpose tools or generally available free+programs which are used unmodified in performing those activities but+which are not part of the work. For example, Corresponding Source+includes interface definition files associated with source files for+the work, and the source code for shared libraries and dynamically+linked subprograms that the work is specifically designed to require,+such as by intimate data communication or control flow between those+subprograms and other parts of the work.++ The Corresponding Source need not include anything that users+can regenerate automatically from other parts of the Corresponding+Source.++ The Corresponding Source for a work in source code form is that+same work.++ 2. Basic Permissions.++ All rights granted under this License are granted for the term of+copyright on the Program, and are irrevocable provided the stated+conditions are met. This License explicitly affirms your unlimited+permission to run the unmodified Program. The output from running a+covered work is covered by this License only if the output, given its+content, constitutes a covered work. This License acknowledges your+rights of fair use or other equivalent, as provided by copyright law.++ You may make, run and propagate covered works that you do not+convey, without conditions so long as your license otherwise remains+in force. You may convey covered works to others for the sole purpose+of having them make modifications exclusively for you, or provide you+with facilities for running those works, provided that you comply with+the terms of this License in conveying all material for which you do+not control copyright. Those thus making or running the covered works+for you must do so exclusively on your behalf, under your direction+and control, on terms that prohibit them from making any copies of+your copyrighted material outside their relationship with you.++ Conveying under any other circumstances is permitted solely under+the conditions stated below. Sublicensing is not allowed; section 10+makes it unnecessary.++ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.++ No covered work shall be deemed part of an effective technological+measure under any applicable law fulfilling obligations under article+11 of the WIPO copyright treaty adopted on 20 December 1996, or+similar laws prohibiting or restricting circumvention of such+measures.++ When you convey a covered work, you waive any legal power to forbid+circumvention of technological measures to the extent such circumvention+is effected by exercising rights under this License with respect to+the covered work, and you disclaim any intention to limit operation or+modification of the work as a means of enforcing, against the work's+users, your or third parties' legal rights to forbid circumvention of+technological measures.++ 4. Conveying Verbatim Copies.++ You may convey verbatim copies of the Program's source code as you+receive it, in any medium, provided that you conspicuously and+appropriately publish on each copy an appropriate copyright notice;+keep intact all notices stating that this License and any+non-permissive terms added in accord with section 7 apply to the code;+keep intact all notices of the absence of any warranty; and give all+recipients a copy of this License along with the Program.++ You may charge any price or no price for each copy that you convey,+and you may offer support or warranty protection for a fee.++ 5. Conveying Modified Source Versions.++ You may convey a work based on the Program, or the modifications to+produce it from the Program, in the form of source code under the+terms of section 4, provided that you also meet all of these conditions:++ a) The work must carry prominent notices stating that you modified+ it, and giving a relevant date.++ b) The work must carry prominent notices stating that it is+ released under this License and any conditions added under section+ 7. This requirement modifies the requirement in section 4 to+ "keep intact all notices".++ c) You must license the entire work, as a whole, under this+ License to anyone who comes into possession of a copy. This+ License will therefore apply, along with any applicable section 7+ additional terms, to the whole of the work, and all its parts,+ regardless of how they are packaged. This License gives no+ permission to license the work in any other way, but it does not+ invalidate such permission if you have separately received it.++ d) If the work has interactive user interfaces, each must display+ Appropriate Legal Notices; however, if the Program has interactive+ interfaces that do not display Appropriate Legal Notices, your+ work need not make them do so.++ A compilation of a covered work with other separate and independent+works, which are not by their nature extensions of the covered work,+and which are not combined with it such as to form a larger program,+in or on a volume of a storage or distribution medium, is called an+"aggregate" if the compilation and its resulting copyright are not+used to limit the access or legal rights of the compilation's users+beyond what the individual works permit. Inclusion of a covered work+in an aggregate does not cause this License to apply to the other+parts of the aggregate.++ 6. Conveying Non-Source Forms.++ You may convey a covered work in object code form under the terms+of sections 4 and 5, provided that you also convey the+machine-readable Corresponding Source under the terms of this License,+in one of these ways:++ a) Convey the object code in, or embodied in, a physical product+ (including a physical distribution medium), accompanied by the+ Corresponding Source fixed on a durable physical medium+ customarily used for software interchange.++ b) Convey the object code in, or embodied in, a physical product+ (including a physical distribution medium), accompanied by a+ written offer, valid for at least three years and valid for as+ long as you offer spare parts or customer support for that product+ model, to give anyone who possesses the object code either (1) a+ copy of the Corresponding Source for all the software in the+ product that is covered by this License, on a durable physical+ medium customarily used for software interchange, for a price no+ more than your reasonable cost of physically performing this+ conveying of source, or (2) access to copy the+ Corresponding Source from a network server at no charge.++ c) Convey individual copies of the object code with a copy of the+ written offer to provide the Corresponding Source. This+ alternative is allowed only occasionally and noncommercially, and+ only if you received the object code with such an offer, in accord+ with subsection 6b.++ d) Convey the object code by offering access from a designated+ place (gratis or for a charge), and offer equivalent access to the+ Corresponding Source in the same way through the same place at no+ further charge. You need not require recipients to copy the+ Corresponding Source along with the object code. If the place to+ copy the object code is a network server, the Corresponding Source+ may be on a different server (operated by you or a third party)+ that supports equivalent copying facilities, provided you maintain+ clear directions next to the object code saying where to find the+ Corresponding Source. Regardless of what server hosts the+ Corresponding Source, you remain obligated to ensure that it is+ available for as long as needed to satisfy these requirements.++ e) Convey the object code using peer-to-peer transmission, provided+ you inform other peers where the object code and Corresponding+ Source of the work are being offered to the general public at no+ charge under subsection 6d.++ A separable portion of the object code, whose source code is excluded+from the Corresponding Source as a System Library, need not be+included in conveying the object code work.++ A "User Product" is either (1) a "consumer product", which means any+tangible personal property which is normally used for personal, family,+or household purposes, or (2) anything designed or sold for incorporation+into a dwelling. In determining whether a product is a consumer product,+doubtful cases shall be resolved in favor of coverage. For a particular+product received by a particular user, "normally used" refers to a+typical or common use of that class of product, regardless of the status+of the particular user or of the way in which the particular user+actually uses, or expects or is expected to use, the product. A product+is a consumer product regardless of whether the product has substantial+commercial, industrial or non-consumer uses, unless such uses represent+the only significant mode of use of the product.++ "Installation Information" for a User Product means any methods,+procedures, authorization keys, or other information required to install+and execute modified versions of a covered work in that User Product from+a modified version of its Corresponding Source. The information must+suffice to ensure that the continued functioning of the modified object+code is in no case prevented or interfered with solely because+modification has been made.++ If you convey an object code work under this section in, or with, or+specifically for use in, a User Product, and the conveying occurs as+part of a transaction in which the right of possession and use of the+User Product is transferred to the recipient in perpetuity or for a+fixed term (regardless of how the transaction is characterized), the+Corresponding Source conveyed under this section must be accompanied+by the Installation Information. But this requirement does not apply+if neither you nor any third party retains the ability to install+modified object code on the User Product (for example, the work has+been installed in ROM).++ The requirement to provide Installation Information does not include a+requirement to continue to provide support service, warranty, or updates+for a work that has been modified or installed by the recipient, or for+the User Product in which it has been modified or installed. Access to a+network may be denied when the modification itself materially and+adversely affects the operation of the network or violates the rules and+protocols for communication across the network.++ Corresponding Source conveyed, and Installation Information provided,+in accord with this section must be in a format that is publicly+documented (and with an implementation available to the public in+source code form), and must require no special password or key for+unpacking, reading or copying.++ 7. Additional Terms.++ "Additional permissions" are terms that supplement the terms of this+License by making exceptions from one or more of its conditions.+Additional permissions that are applicable to the entire Program shall+be treated as though they were included in this License, to the extent+that they are valid under applicable law. If additional permissions+apply only to part of the Program, that part may be used separately+under those permissions, but the entire Program remains governed by+this License without regard to the additional permissions.++ When you convey a copy of a covered work, you may at your option+remove any additional permissions from that copy, or from any part of+it. (Additional permissions may be written to require their own+removal in certain cases when you modify the work.) You may place+additional permissions on material, added by you to a covered work,+for which you have or can give appropriate copyright permission.++ Notwithstanding any other provision of this License, for material you+add to a covered work, you may (if authorized by the copyright holders of+that material) supplement the terms of this License with terms:++ a) Disclaiming warranty or limiting liability differently from the+ terms of sections 15 and 16 of this License; or++ b) Requiring preservation of specified reasonable legal notices or+ author attributions in that material or in the Appropriate Legal+ Notices displayed by works containing it; or++ c) Prohibiting misrepresentation of the origin of that material, or+ requiring that modified versions of such material be marked in+ reasonable ways as different from the original version; or++ d) Limiting the use for publicity purposes of names of licensors or+ authors of the material; or++ e) Declining to grant rights under trademark law for use of some+ trade names, trademarks, or service marks; or++ f) Requiring indemnification of licensors and authors of that+ material by anyone who conveys the material (or modified versions of+ it) with contractual assumptions of liability to the recipient, for+ any liability that these contractual assumptions directly impose on+ those licensors and authors.++ All other non-permissive additional terms are considered "further+restrictions" within the meaning of section 10. If the Program as you+received it, or any part of it, contains a notice stating that it is+governed by this License along with a term that is a further+restriction, you may remove that term. If a license document contains+a further restriction but permits relicensing or conveying under this+License, you may add to a covered work material governed by the terms+of that license document, provided that the further restriction does+not survive such relicensing or conveying.++ If you add terms to a covered work in accord with this section, you+must place, in the relevant source files, a statement of the+additional terms that apply to those files, or a notice indicating+where to find the applicable terms.++ Additional terms, permissive or non-permissive, may be stated in the+form of a separately written license, or stated as exceptions;+the above requirements apply either way.++ 8. Termination.++ You may not propagate or modify a covered work except as expressly+provided under this License. Any attempt otherwise to propagate or+modify it is void, and will automatically terminate your rights under+this License (including any patent licenses granted under the third+paragraph of section 11).++ However, if you cease all violation of this License, then your+license from a particular copyright holder is reinstated (a)+provisionally, unless and until the copyright holder explicitly and+finally terminates your license, and (b) permanently, if the copyright+holder fails to notify you of the violation by some reasonable means+prior to 60 days after the cessation.++ Moreover, your license from a particular copyright holder is+reinstated permanently if the copyright holder notifies you of the+violation by some reasonable means, this is the first time you have+received notice of violation of this License (for any work) from that+copyright holder, and you cure the violation prior to 30 days after+your receipt of the notice.++ Termination of your rights under this section does not terminate the+licenses of parties who have received copies or rights from you under+this License. If your rights have been terminated and not permanently+reinstated, you do not qualify to receive new licenses for the same+material under section 10.++ 9. Acceptance Not Required for Having Copies.++ You are not required to accept this License in order to receive or+run a copy of the Program. Ancillary propagation of a covered work+occurring solely as a consequence of using peer-to-peer transmission+to receive a copy likewise does not require acceptance. However,+nothing other than this License grants you permission to propagate or+modify any covered work. These actions infringe copyright if you do+not accept this License. Therefore, by modifying or propagating a+covered work, you indicate your acceptance of this License to do so.++ 10. Automatic Licensing of Downstream Recipients.++ Each time you convey a covered work, the recipient automatically+receives a license from the original licensors, to run, modify and+propagate that work, subject to this License. You are not responsible+for enforcing compliance by third parties with this License.++ An "entity transaction" is a transaction transferring control of an+organization, or substantially all assets of one, or subdividing an+organization, or merging organizations. If propagation of a covered+work results from an entity transaction, each party to that+transaction who receives a copy of the work also receives whatever+licenses to the work the party's predecessor in interest had or could+give under the previous paragraph, plus a right to possession of the+Corresponding Source of the work from the predecessor in interest, if+the predecessor has it or can get it with reasonable efforts.++ You may not impose any further restrictions on the exercise of the+rights granted or affirmed under this License. For example, you may+not impose a license fee, royalty, or other charge for exercise of+rights granted under this License, and you may not initiate litigation+(including a cross-claim or counterclaim in a lawsuit) alleging that+any patent claim is infringed by making, using, selling, offering for+sale, or importing the Program or any portion of it.++ 11. Patents.++ A "contributor" is a copyright holder who authorizes use under this+License of the Program or a work on which the Program is based. The+work thus licensed is called the contributor's "contributor version".++ A contributor's "essential patent claims" are all patent claims+owned or controlled by the contributor, whether already acquired or+hereafter acquired, that would be infringed by some manner, permitted+by this License, of making, using, or selling its contributor version,+but do not include claims that would be infringed only as a+consequence of further modification of the contributor version. For+purposes of this definition, "control" includes the right to grant+patent sublicenses in a manner consistent with the requirements of+this License.++ Each contributor grants you a non-exclusive, worldwide, royalty-free+patent license under the contributor's essential patent claims, to+make, use, sell, offer for sale, import and otherwise run, modify and+propagate the contents of its contributor version.++ In the following three paragraphs, a "patent license" is any express+agreement or commitment, however denominated, not to enforce a patent+(such as an express permission to practice a patent or covenant not to+sue for patent infringement). To "grant" such a patent license to a+party means to make such an agreement or commitment not to enforce a+patent against the party.++ If you convey a covered work, knowingly relying on a patent license,+and the Corresponding Source of the work is not available for anyone+to copy, free of charge and under the terms of this License, through a+publicly available network server or other readily accessible means,+then you must either (1) cause the Corresponding Source to be so+available, or (2) arrange to deprive yourself of the benefit of the+patent license for this particular work, or (3) arrange, in a manner+consistent with the requirements of this License, to extend the patent+license to downstream recipients. "Knowingly relying" means you have+actual knowledge that, but for the patent license, your conveying the+covered work in a country, or your recipient's use of the covered work+in a country, would infringe one or more identifiable patents in that+country that you have reason to believe are valid.++ If, pursuant to or in connection with a single transaction or+arrangement, you convey, or propagate by procuring conveyance of, a+covered work, and grant a patent license to some of the parties+receiving the covered work authorizing them to use, propagate, modify+or convey a specific copy of the covered work, then the patent license+you grant is automatically extended to all recipients of the covered+work and works based on it.++ A patent license is "discriminatory" if it does not include within+the scope of its coverage, prohibits the exercise of, or is+conditioned on the non-exercise of one or more of the rights that are+specifically granted under this License. You may not convey a covered+work if you are a party to an arrangement with a third party that is+in the business of distributing software, under which you make payment+to the third party based on the extent of your activity of conveying+the work, and under which the third party grants, to any of the+parties who would receive the covered work from you, a discriminatory+patent license (a) in connection with copies of the covered work+conveyed by you (or copies made from those copies), or (b) primarily+for and in connection with specific products or compilations that+contain the covered work, unless you entered into that arrangement,+or that patent license was granted, prior to 28 March 2007.++ Nothing in this License shall be construed as excluding or limiting+any implied license or other defenses to infringement that may+otherwise be available to you under applicable patent law.++ 12. No Surrender of Others' Freedom.++ If conditions are imposed on you (whether by court order, agreement or+otherwise) that contradict the conditions of this License, they do not+excuse you from the conditions of this License. If you cannot convey a+covered work so as to satisfy simultaneously your obligations under this+License and any other pertinent obligations, then as a consequence you may+not convey it at all. For example, if you agree to terms that obligate you+to collect a royalty for further conveying from those to whom you convey+the Program, the only way you could satisfy both those terms and this+License would be to refrain entirely from conveying the Program.++ 13. Use with the GNU Affero General Public License.++ Notwithstanding any other provision of this License, you have+permission to link or combine any covered work with a work licensed+under version 3 of the GNU Affero General Public License into a single+combined work, and to convey the resulting work. The terms of this+License will continue to apply to the part which is the covered work,+but the special requirements of the GNU Affero General Public License,+section 13, concerning interaction through a network will apply to the+combination as such.++ 14. Revised Versions of this License.++ The Free Software Foundation may publish revised and/or new versions of+the GNU General Public License from time to time. Such new versions will+be similar in spirit to the present version, but may differ in detail to+address new problems or concerns.++ Each version is given a distinguishing version number. If the+Program specifies that a certain numbered version of the GNU General+Public License "or any later version" applies to it, you have the+option of following the terms and conditions either of that numbered+version or of any later version published by the Free Software+Foundation. If the Program does not specify a version number of the+GNU General Public License, you may choose any version ever published+by the Free Software Foundation.++ If the Program specifies that a proxy can decide which future+versions of the GNU General Public License can be used, that proxy's+public statement of acceptance of a version permanently authorizes you+to choose that version for the Program.++ Later license versions may give you additional or different+permissions. However, no additional obligations are imposed on any+author or copyright holder as a result of your choosing to follow a+later version.++ 15. Disclaimer of Warranty.++ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.++ 16. Limitation of Liability.++ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF+SUCH DAMAGES.++ 17. Interpretation of Sections 15 and 16.++ If the disclaimer of warranty and limitation of liability provided+above cannot be given local legal effect according to their terms,+reviewing courts shall apply local law that most closely approximates+an absolute waiver of all civil liability in connection with the+Program, unless a warranty or assumption of liability accompanies a+copy of the Program in return for a fee.++ END OF TERMS AND CONDITIONS++ How to Apply These Terms to Your New Programs++ If you develop a new program, and you want it to be of the greatest+possible use to the public, the best way to achieve this is to make it+free software which everyone can redistribute and change under these terms.++ To do so, attach the following notices to the program. It is safest+to attach them to the start of each source file to most effectively+state the exclusion of warranty; and each file should have at least+the "copyright" line and a pointer to where the full notice is found.++ <one line to give the program's name and a brief idea of what it does.>+ Copyright (C) <year> <name of author>++ This program is free software: you can redistribute it and/or modify+ it under the terms of the GNU General Public License as published by+ the Free Software Foundation, either version 3 of the License, or+ (at your option) any later version.++ This program is distributed in the hope that it will be useful,+ but WITHOUT ANY WARRANTY; without even the implied warranty of+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ GNU General Public License for more details.++ You should have received a copy of the GNU General Public License+ along with this program. If not, see <http://www.gnu.org/licenses/>.++Also add information on how to contact you by electronic and paper mail.++ If the program does terminal interaction, make it output a short+notice like this when it starts in an interactive mode:++ <program> Copyright (C) <year> <name of author>+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.+ This is free software, and you are welcome to redistribute it+ under certain conditions; type `show c' for details.++The hypothetical commands `show w' and `show c' should show the appropriate+parts of the General Public License. Of course, your program's commands+might be different; for a GUI interface, you would use an "about box".++ You should also get your employer (if you work as a programmer) or school,+if any, to sign a "copyright disclaimer" for the program, if necessary.+For more information on this, and how to apply and follow the GNU GPL, see+<http://www.gnu.org/licenses/>.++ The GNU General Public License does not permit incorporating your program+into proprietary programs. If your program is a subroutine library, you+may consider it more useful to permit linking proprietary applications with+the library. If this is what you want to do, use the GNU Lesser General+Public License instead of this License. But first, please read+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
+ Control/Applicative/Constrained.hs view
@@ -0,0 +1,106 @@+-- |+-- Module : Control.Applicative.Constrained+-- Copyright : (c) 2013 Justus Sagemüller+-- License : GPL v3 (see COPYING)+-- Maintainer : (@) sagemueller $ geo.uni-koeln.de+-- +{-# LANGUAGE ConstraintKinds #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE FunctionalDependencies #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE ScopedTypeVariables #-}+++module Control.Applicative.Constrained ( + module Control.Functor.Constrained+ -- * Monoidal / applicative functors+ , Monoidal(..)+ , Applicative(..)+ -- * Helper for constrained categories+ , constrainedFZipWith+ -- * Utility functions+ , constPure, fzip, (<**>), liftA, liftA2, liftA3+ ) where+++import Control.Functor.Constrained+import Control.Arrow.Constrained++import Prelude hiding (id, const, (.), ($), Functor(..), curry, uncurry)+import qualified Control.Category.Hask as Hask+++class (Functor f r t, Cartesian r, Cartesian t) => Monoidal f r t where+ pureUnit :: UnitObject t `t` f (UnitObject r)+ fzipWith :: (ObjectPair r a b, Object r c, ObjectPair t (f a) (f b), Object t (f c))+ => r (a, b) c -> t (f a, f b) (f c)++constPure :: (WellPointed r, Monoidal f r t, ObjectPoint r a, Object t (f a) )+ => a -> t (UnitObject t) (f a)+constPure a = fmap (const a) . pureUnit++fzip :: (Monoidal f r t, ObjectPair r a b, ObjectPair t (f a) (f b), Object t (f (a,b)))+ => t (f a, f b) (f (a,b))+fzip = fzipWith id++class (Monoidal f r t, Curry r, Curry t) => Applicative f r t where+ -- ^ Note that this tends to make little sense for non-endofunctors. + -- Consider using 'constPure' instead.+ pure :: (Object r a, Object t (f a)) => a `t` f a + + (<*>) :: ( ObjectMorphism r a b+ , ObjectMorphism t (f a) (f b), Object t (t (f a) (f b))+ , ObjectPair r (r a b) a, ObjectPair t (f (r a b)) (f a)+ , Object r a, Object r b )+ => f (r a b) `t` t (f a) (f b)+ (<*>) = curry (fzipWith $ uncurry id)++infixl 4 <*>+ +(<**>) :: ( Applicative f r (->), ObjectMorphism r a b, ObjectPair r (r a b) a )+ => f a -> f (r a b) -> f b+(<**>) = flip $ curry (fzipWith $ uncurry id)++liftA :: (Applicative f r t, Object r a, Object r b, Object t (f a), Object t (f b)) + => a `r` b -> f a `t` f b+liftA = fmap++liftA2 :: ( Applicative f r t, Object r c, ObjectMorphism r b c+ , Object t (f c), ObjectMorphism t (f b) (f c) + , ObjectPair r a b, ObjectPair t (f a) (f b) ) + => a `r` (b `r` c) -> f a `t` (f b `t` f c)+liftA2 = curry . fzipWith . uncurry++liftA3 :: ( Applicative f r t+ , Object r c, Object r d+ , ObjectMorphism r c d, ObjectMorphism r b (c`r`d), Object r (r c d)+ , ObjectPair r a b, ObjectPair r (r c d) c + , Object t (f c), Object t (f d), Object t(f a,f b)+ , ObjectMorphism t (f c)(f d),ObjectMorphism t (f b)(t(f c)(f d)),Object t(t(f c)(f d))+ , ObjectPair t (f a) (f b), ObjectPair t (t (f c) (f d)) (f c)+ , ObjectPair t (f (r c d)) (f c)+ ) => a `r` (b `r` (c `r` d)) -> f a `t` (f b `t` (f c `t` f d))+liftA3 f = curry $ (<*>) . (fzipWith $ uncurry f)+++constrainedFZipWith :: ( Category r, Category t, o a, o b, o (a,b), o c+ , o (f a, f b), o (f c) )+ => ( r (a, b) c -> t (f a, f b) (f c) )+ -> ConstrainedCategory r o (a, b) c -> ConstrainedCategory t o (f a, f b) (f c)+constrainedFZipWith zf = constrained . zf . unconstrained+ ++instance (Hask.Applicative f) => Monoidal f (->) (->) where+ pureUnit = Hask.pure+ fzipWith f (p, q) = curry f Hask.<$> p Hask.<*> q++instance (Hask.Applicative f) => Applicative f (->) (->) where+ pure = Hask.pure+ (<*>) = (Hask.<*>)++ ++ +
+ Control/Arrow/Constrained.hs view
@@ -0,0 +1,424 @@+-- |+-- Module : Control.Arrow.Constrained+-- Copyright : (c) 2013 Justus Sagemüller+-- License : GPL v3 (see COPYING)+-- Maintainer : (@) sagemueller $ geo.uni-koeln.de+-- +-- Haskell's 'Arr.Arrow's, going back to [Hughes 2000], combine multiple ideas from+-- category theory:+-- +-- * They expand upon cartesian categories, by offering ways to combine arrows between+-- simple objects to composite ones working on tuples (i.e. /products/) thereof.+-- +-- * They constitute a \"profunctor\" interface, allowing to \"@fmap@\" both covariantly+-- over the second parameter, as well as contravariantly over the first. As in case+-- of "Control.Functor.Constrained", we wish the underlying category to fmap from+-- not to be limited to /Hask/, so 'Arrow' also has an extra parameter.+-- +-- To facilitate these somewhat divergent needs, 'Arrow' is split up in three classes.+-- These do not even form an ordinary hierarchy, to allow categories to implement+-- only one /or/ the other aspect.+-- +-- That's not the only significant difference of this module, compared to "Control.Arrow":+-- +-- * Kleisli arrows are not defined here, but in "Control.Monad.Constrained".+-- Monads are really a much more specific concept than category arrows.+-- +-- * Some extra utilities are included that don't apparently have much to+-- do with 'Arrow' at all, but require the expanded cartesian-category tools+-- and are therefore not in "Control.Category.Constrained".++{-# LANGUAGE ConstraintKinds #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE FunctionalDependencies #-}+{-# LANGUAGE TupleSections #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE UndecidableInstances #-}+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE AllowAmbiguousTypes #-}+++module Control.Arrow.Constrained (+ -- * The Arrow type classes+ Arrow, Morphism(..), PreArrow(..), WellPointed(..),ObjectPoint, EnhancedCat(..)+ -- * Dual / "choice" arrows+ , ArrowChoice, MorphChoice(..), PreArrChoice(..)+ -- * Distributive law between sum- and product objects+ , SPDistribute(..) + -- * Function-like categories+ , Function, ($)+ -- * Alternative composition notation+ , (>>>), (<<<)+ -- * Proxies for cartesian categories+ , CartesianProxy(..)+ , genericProxyCombine, genericUnit, genericAlg1to2, genericAlg2to1, genericAlg2to2+ , PointProxy(..), genericPoint+ -- * Misc utility+ -- ** Conditionals+ , choose, ifThenElse+ ) where++import Prelude hiding (id, const, fst, snd, (.), ($), Functor(..), Monad(..), (=<<))+import Control.Category.Constrained+import qualified Control.Category.Hask as Hask++import GHC.Exts (Constraint)+import Data.Tagged+import Data.Void++import qualified Control.Arrow as Arr++infixr 1 >>>, <<<+infixr 3 &&&, ***++(>>>) :: (Category k, Object k a, Object k b, Object k c) + => k a b -> k b c -> k a c+(>>>) = flip (.)+(<<<) :: (Category k, Object k a, Object k b, Object k c) + => k b c -> k a b -> k a c+(<<<) = (.)++class (Cartesian a) => Morphism a where+ first :: ( ObjectPair a b d, ObjectPair a c d )+ => a b c -> a (b, d) (c, d)+ first = (***id)+ second :: ( ObjectPair a d b, ObjectPair a d c )+ => a b c -> a (d, b) (d, c)+ second = (id***)+ (***) :: ( ObjectPair a b b', ObjectPair a c c' )+ => a b c -> a b' c' -> a (b,b') (c,c')++-- | Dual to 'Morphism', dealing with sums instead of products.+class (CoCartesian a) => MorphChoice a where+ left :: ( ObjectSum a b d, ObjectSum a c d )+ => a b c -> a (b+d) (c+d)+ left = (+++id)+ right :: ( ObjectSum a d b, ObjectSum a d c )+ => a b c -> a (d+b) (d+c)+ right = (id+++)+ (+++) :: ( ObjectSum a b b', ObjectSum a c c' )+ => a b c -> a b' c' -> a (b+b') (c+c')++++-- | Unlike 'first', 'second', '***' and 'arr', '&&&' has an intrinsic notion+-- of \"direction\": it is basically equivalent to precomposing the result+-- of '***' with a @b -> (b,b)@, but that is in general only available+-- for arrows that generalise ordinary functions, in their native direction.+-- (@(b,b) ->b@ is specific to semigroups.) It is for this reason the only constituent+-- class of 'Arrow' that actually has \"arrow\" in its name.+-- +-- In terms of category theory, this \"direction\" reflects the distinction+-- between /initial-/ and /terminal objects/. The latter are more interesting,+-- basically what 'UnitObject' is useful for. It gives rise to the tuple+-- selector morphisms as well.+class (Morphism a) => PreArrow a where+ (&&&) :: ( Object a b, ObjectPair a c c' )+ => a b c -> a b c' -> a b (c,c')+ terminal :: ( Object a b ) => a b (UnitObject a)+ fst :: (ObjectPair a x y) => a (x,y) x+ snd :: (ObjectPair a x y) => a (x,y) y++infixr 2 |||+-- | Dual to 'PreArrow', this class deals with the vacuous initial (zero) objects,+-- but also more usefully with choices / sums.+-- This represents the most part of 'Hask.ArrowChoice'.+class (MorphChoice k) => PreArrChoice k where+ (|||) :: ( ObjectSum k b b', Object k c )+ => k b c -> k b' c -> k (b+b') c+ -- | This is basically 'absurd'.+ initial :: ( Object k b ) => k (ZeroObject k) b+ -- | Perhaps @lft@ and @rgt@ would be more consequent names, but likely more confusing as well.+ coFst :: (ObjectSum k a b) => k a (a+b)+ coSnd :: (ObjectSum k a b) => k b (a+b)+++-- | Like in arithmetics, the distributive law+-- @a ⋅ (b + c) ≈ (a ⋅ b) + (a ⋅ c)@+-- holds for Haskell types – in the usual isomorphism sense. But like many such+-- isomorphisms that are trivial to inline in /Hask/, this is not necessarily the case+-- for general categories.+class (PreArrow k, PreArrChoice k) => SPDistribute k where+ distribute :: ( ObjectSum k (a,b) (a,c), ObjectPair k a (b+c)+ , ObjectSum k b c, PairObjects k a b, PairObjects k a c )+ => k (a, b+c) ((a,b)+(a,c))+ unDistribute :: ( ObjectSum k (a,b) (a,c), ObjectPair k a (b+c)+ , ObjectSum k b c, PairObjects k a b, PairObjects k a c )+ => k ((a,b)+(a,c)) (a, b+c)+ boolAsSwitch :: ( ObjectSum k a a, ObjectPair k Bool a ) => k (Bool,a) (a+a)+ boolFromSwitch :: ( ObjectSum k a a, ObjectPair k Bool a ) => k (a+a) (Bool,a)+-- boolFromSwitch = (boolFromSum <<< terminal +++ terminal) &&& (id ||| id)++instance ( SPDistribute k + , ObjectSum k (a,b) (a,c), ObjectPair k a (b+c)+ , ObjectSum k b c, PairObjects k a b, PairObjects k a c+ ) => Isomorphic k (a, b+c) ((a,b)+(a,c)) where+ iso = distribute+instance ( SPDistribute k + , ObjectSum k (a,b) (a,c), ObjectPair k a (b+c)+ , ObjectSum k b c, PairObjects k a b, PairObjects k a c+ ) => Isomorphic k ((a,b)+(a,c)) (a, b+c) where+ iso = unDistribute+instance ( SPDistribute k + , ObjectSum k a a, ObjectPair k Bool a+ ) => Isomorphic k (Bool, a) (a+a) where+ iso = boolAsSwitch+instance ( SPDistribute k + , ObjectSum k a a, ObjectPair k Bool a+ ) => Isomorphic k (a+a) (Bool, a) where+ iso = boolFromSwitch++ ++-- | 'WellPointed' expresses the relation between your category's objects+-- and the values of the Haskell data types (which is, after all, what objects are+-- in this library). Specifically, this class allows you to \"point\" on+-- specific objects, thus making out a value of that type as a point of the object.+-- +-- Perhaps easier than thinking about what that's supposed to mean is noting+-- this class contains 'const'. Thus 'WellPointed' is /almost/ the+-- traditional 'Hask.Arrow': it lets you express all the natural transformations+-- and inject constant values, only you can't just promote arbitrary functions+-- to arrows of the category.+-- +-- Unlike with 'Morphism' and 'PreArrow', a literal dual of 'WellPointed' does+-- not seem useful.+class (PreArrow a, ObjectPoint a (UnitObject a)) => WellPointed a where+ {-# MINIMAL unit, (globalElement | const) #-}+ type PointObject a x :: Constraint+ type PointObject a x = ()+ globalElement :: (ObjectPoint a x) => x -> a (UnitObject a) x+ globalElement = const+ unit :: CatTagged a (UnitObject a)+ const :: (Object a b, ObjectPoint a x) + => x -> a b x+ const x = globalElement x . terminal++type ObjectPoint k a = (Object k a, PointObject k a)+ +-- -- | 'WellPointed' does not have a useful literal dual.+-- class (PreArrChoice a, ObjectPoint a (ZeroObject a)) => WellChosen a where+-- type ChoiceObject a x :: Constraint+-- type ChoiceObject a x = ()+-- localElement :: (ObjectChoice a x) => a x (ZeroObject a) -> (x -> b+-- zero :: CatTagged a (ZeroObject a)+-- doomed :: (Object a b, ObjectChoice a x) +-- => x -> a x b+-- doomed x = globalElement x . initial+-- +-- type ObjectChoice k a = (Object k a, ChoiceObject k x)+-- +value :: forall f x . (WellPointed f, Function f, Object f x)+ => f (UnitObject f) x -> x+value f = f $ untag(unit :: Tagged (f (UnitObject f) (UnitObject f)) (UnitObject f))+++class (Category k) => EnhancedCat a k where+ arr :: (Object k b, Object k c, Object a b, Object a c)+ => k b c -> a b c+instance (Category k) => EnhancedCat k k where+ arr = id+++-- | Many categories have as morphisms essentially /functions with extra properties/:+-- group homomorphisms, linear maps, continuous functions...+-- +-- It makes sense to generalise the notion of function application to these+-- morphisms; we can't do that for the simple juxtaposition writing @f x@,+-- but it is possible for the function-application operator @$@.+-- +-- This is particularly useful for 'ConstrainedCategory' versions of Hask,+-- where after all the morphisms are /nothing but functions/.+type Function f = EnhancedCat (->) f++infixr 0 $+($) :: (Function f, Object f a, Object f b) => f a b -> a -> b+f $ x = arr f x++instance (Function f) => EnhancedCat (->) (ConstrainedCategory f o) where+ arr (ConstrainedMorphism q) = arr q++++type Arrow a k = (WellPointed a, EnhancedCat a k)+type ArrowChoice a k = (WellPointed a, PreArrChoice a, EnhancedCat a k)++instance Morphism (->) where+ first = Arr.first+ second = Arr.second+ (***) = (Arr.***)+instance MorphChoice (->) where+ left = Arr.left+ right = Arr.right+ (+++) = (Arr.+++)+instance PreArrow (->) where+ (&&&) = (Arr.&&&)+ fst (a,_) = a+ snd (_,b) = b+ terminal = const ()+instance PreArrChoice (->) where+ (|||) = (Arr.|||)+ coFst a = Left a+ coSnd b = Right b+ initial = absurd+instance SPDistribute (->) where+ distribute (a, Left b) = Left (a,b)+ distribute (a, Right c) = Right (a,c)+ unDistribute (Left (a,b)) = (a, Left b)+ unDistribute (Right (a,c)) = (a, Right c)+ boolAsSwitch (False, a) = Left a+ boolAsSwitch (True, a) = Right a+ boolFromSwitch (Left a) = (False, a)+ boolFromSwitch (Right a) = (True, a)+instance WellPointed (->) where+ globalElement = Hask.const+ unit = Hask.pure ()+ const = Hask.const++constrainedArr :: (Category k, Category a, o b, o c )+ => ( k b c -> a b c )+ -> k b c -> ConstrainedCategory a o b c+constrainedArr ar = constrained . ar++constrainedFirst :: ( Category a, Cartesian a, ObjectPair a b d, ObjectPair a c d )+ => ( a b c -> a (b, d) (c, d) )+ -> ConstrainedCategory a o b c -> ConstrainedCategory a o (b, d) (c, d)+constrainedFirst fs = ConstrainedMorphism . fs . unconstrained+ +constrainedSecond :: ( Category a, Cartesian a, ObjectPair a d b, ObjectPair a d c )+ => ( a b c -> a (d, b) (d, c) )+ -> ConstrainedCategory a o b c -> ConstrainedCategory a o (d, b) (d, c)+constrainedSecond sn = ConstrainedMorphism . sn . unconstrained+++instance (Morphism a, o (UnitObject a)) => Morphism (ConstrainedCategory a o) where+ first = constrainedFirst first+ second = constrainedSecond second+ ConstrainedMorphism a *** ConstrainedMorphism b = ConstrainedMorphism $ a *** b+ +instance (PreArrow a, o (UnitObject a)) => PreArrow (ConstrainedCategory a o) where+ ConstrainedMorphism a &&& ConstrainedMorphism b = ConstrainedMorphism $ a &&& b+ terminal = ConstrainedMorphism terminal+ fst = ConstrainedMorphism fst+ snd = ConstrainedMorphism snd++instance (WellPointed a, o (UnitObject a)) => WellPointed (ConstrainedCategory a o) where+ type PointObject (ConstrainedCategory a o) x = PointObject a x+ globalElement x = ConstrainedMorphism $ globalElement x+ unit = cstrCatUnit+ const x = ConstrainedMorphism $ const x++cstrCatUnit :: forall a o . (WellPointed a, o (UnitObject a))+ => CatTagged (ConstrainedCategory a o) (UnitObject a)+cstrCatUnit = retag (unit :: CatTagged a (UnitObject a))+ +instance (Arrow a k, o (UnitObject a)) => EnhancedCat (ConstrainedCategory a o) k where+ arr = constrainedArr arr +++constrainedLeft :: ( CoCartesian k, ObjectSum k b d, ObjectSum k c d )+ => ( k b c -> k (b+d) (c+d) )+ -> ConstrainedCategory k o b c -> ConstrainedCategory k o (b+d) (c+d)+constrainedLeft fs = ConstrainedMorphism . fs . unconstrained+ +constrainedRight :: ( CoCartesian k, ObjectSum k b c, ObjectSum k b d )+ => ( k c d -> k (b+c) (b+d) )+ -> ConstrainedCategory k o c d -> ConstrainedCategory k o (b+c) (b+d)+constrainedRight fs = ConstrainedMorphism . fs . unconstrained++instance (MorphChoice k, o (ZeroObject k)) => MorphChoice (ConstrainedCategory k o) where+ left = constrainedLeft left+ right = constrainedRight right+ ConstrainedMorphism a +++ ConstrainedMorphism b = ConstrainedMorphism $ a +++ b+ +instance (PreArrChoice k, o (ZeroObject k)) => PreArrChoice (ConstrainedCategory k o) where+ ConstrainedMorphism a ||| ConstrainedMorphism b = ConstrainedMorphism $ a ||| b+ initial = ConstrainedMorphism initial+ coFst = ConstrainedMorphism coFst+ coSnd = ConstrainedMorphism coSnd++instance (SPDistribute k, o (ZeroObject k), o (UnitObject k))+ => SPDistribute (ConstrainedCategory k o) where+ distribute = ConstrainedMorphism distribute+ unDistribute = ConstrainedMorphism unDistribute+ boolAsSwitch = ConstrainedMorphism boolAsSwitch+ boolFromSwitch = ConstrainedMorphism boolFromSwitch+ +++-- | Basically 'ifThenElse' with inverted argument order, and+-- \"morphismised\" arguments.+choose :: (Arrow f (->), Function f, Object f Bool, Object f a)+ => f (UnitObject f) a -- ^ \"'False'\" value+ -> f (UnitObject f) a -- ^ \"'True'\" value+ -> f Bool a+choose fv tv = arr $ \c -> if c then value tv else value fv++ifThenElse :: ( EnhancedCat f (->), Function f+ , Object f Bool, Object f a, Object f (f a a), Object f (f a (f a a))+ ) => Bool `f` (a `f` (a `f` a))+ifThenElse = arr $ \c -> arr $ \tv -> arr $ \fv -> if c then tv else fv++ +++genericProxyCombine :: ( HasProxy k, PreArrow k+ , Object k a, ObjectPair k b c, Object k d )+ => k (b,c) d -> GenericProxy k a b -> GenericProxy k a c -> GenericProxy k a d+genericProxyCombine m (GenericProxy v) (GenericProxy w)+ = GenericProxy $ m . (v &&& w)+ +genericUnit :: ( PreArrow k, HasProxy k, Object k a )+ => GenericProxy k a (UnitObject k)+genericUnit = GenericProxy terminal+++class (Morphism k, HasProxy k) => CartesianProxy k where+ alg1to2 :: ( Object k a, ObjectPair k b c+ ) => (forall q . Object k q+ => ProxyVal k q a -> (ProxyVal k q b, ProxyVal k q c) )+ -> k a (b,c)+ alg2to1 :: ( ObjectPair k a b, Object k c+ ) => (forall q . Object k q+ => ProxyVal k q a -> ProxyVal k q b -> ProxyVal k q c )+ -> k (a,b) c+ alg2to2 :: ( ObjectPair k a b, ObjectPair k c d+ ) => (forall q . Object k q+ => ProxyVal k q a -> ProxyVal k q b -> (ProxyVal k q c, ProxyVal k q d) )+ -> k (a,b) (c,d)++genericAlg1to2 :: ( PreArrow k, u ~ UnitObject k+ , Object k a, ObjectPair k b c+ ) => ( forall q . Object k q+ => GenericProxy k q a -> (GenericProxy k q b, GenericProxy k q c) )+ -> k a (b,c)+genericAlg1to2 f = runGenericProxy b &&& runGenericProxy c+ where (b,c) = f $ GenericProxy id+genericAlg2to1 :: ( PreArrow k, u ~ UnitObject k+ , ObjectPair k a u, ObjectPair k a b, ObjectPair k b u, ObjectPair k b a+ ) => ( forall q . Object k q+ => GenericProxy k q a -> GenericProxy k q b -> GenericProxy k q c )+ -> k (a,b) c+genericAlg2to1 f = runGenericProxy $ f (GenericProxy fst) (GenericProxy snd)+genericAlg2to2 :: ( PreArrow k, u ~ UnitObject k+ , ObjectPair k a u, ObjectPair k a b, ObjectPair k c d+ , ObjectPair k b u, ObjectPair k b a+ ) => ( forall q . Object k q+ => GenericProxy k q a -> GenericProxy k q b + -> (GenericProxy k q c, GenericProxy k q d) )+ -> k (a,b) (c,d)+genericAlg2to2 f = runGenericProxy c &&& runGenericProxy d+ where (c,d) = f (GenericProxy fst) (GenericProxy snd)+++class (HasProxy k, ProxyVal k a x ~ p a x) + => PointProxy p k a x | p -> k where+ point :: (Object k a, Object k x) => x -> p a x++genericPoint :: ( WellPointed k, Object k a, ObjectPoint k x )+ => x -> GenericProxy k a x+genericPoint x = GenericProxy $ const x+
+ Control/Category/Constrained.hs view
@@ -0,0 +1,402 @@+-- |+-- Module : Control.Category.Constrained+-- Copyright : (c) 2013 Justus Sagemüller+-- License : GPL v3 (see COPYING)+-- Maintainer : (@) sagemueller $ geo.uni-koeln.de+-- +-- +-- The most basic category theory tools are included partly in this+-- module, partly in "Control.Arrow.Constrained".++{-# LANGUAGE ConstraintKinds #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE AllowAmbiguousTypes #-}+{-# LANGUAGE TypeOperators #-}++module Control.Category.Constrained ( + -- * The category class+ Category (..)+ -- * Monoidal categories+ , Cartesian (..), ObjectPair+ , Curry (..), ObjectMorphism+ -- * Monoidal with coproducts+ , (+)()+ , CoCartesian (..), ObjectSum+ -- * Isomorphisms+ , Isomorphic (..)+ -- * Constraining a category+ , ConstrainedCategory (ConstrainedMorphism)+ , constrained, unconstrained+ -- * Global-element proxies+ , HasProxy (..)+ , genericAlg, genericProxyMap+ , GenericProxy (..)+ -- * Utility+ , inCategoryOf+ , CatTagged+ ) where++import Prelude hiding (id, (.), curry, uncurry)+import qualified Prelude+import GHC.Exts (Constraint)+import Data.Tagged+import Data.Monoid+import Data.Void++-- | In mathematics, a category is defined as a class of /objects/, plus a class of+-- /morphisms/ between those objects. In Haskell, one traditionally works in+-- the category @(->)@ (called /Hask/), in which /any Haskell type/ is an object. +-- But of course+-- there are lots of useful categories where the objects are much more specific,+-- e.g. vector spaces with linear maps as morphisms. The obvious way to express+-- this in Haskell is as type class constraints, and the @ConstraintKinds@ extension+-- allows quantifying over such object classes.+-- +-- Like in "Control.Category", \"the category @k@\" means actually @k@ is the +-- /morphism type constructor/. From a mathematician's point of view this may+-- seem a bit strange way to define the category, but it just turns out to+-- be quite convenient for practical purposes.+class Category k where+ type Object k o :: Constraint+ type Object k o = ()+ id :: Object k a => k a a+ (.) :: (Object k a, Object k b, Object k c) + => k b c -> k a b -> k a c++infixr 9 .++instance Category (->) where+ id = Prelude.id+ (.) = (Prelude..)++-- | Analogue to 'asTypeOf', this does not actually do anything but can+-- give the compiler type unification hints in a convenient manner.+inCategoryOf :: (Category k) => k a b -> k c d -> k a b+m `inCategoryOf` _ = m+++-- | A given category can be specialised, by using the same morphisms but adding+-- extra constraints to what is considered an object. +-- +-- For instance, @'ConstrainedCategory' (->) 'Ord'@ is the category of all+-- totally ordered data types (but with arbitrary functions; this does not require+-- monotonicity or anything).+newtype ConstrainedCategory (k :: * -> * -> *) (o :: * -> Constraint) (a :: *) (b :: *)+ = ConstrainedMorphism { unconstrainedMorphism :: k a b }++-- | Cast a morphism to its equivalent in a more constrained category,+-- provided it connects objects that actually satisfy the extra constraint.+constrained :: (Category k, o a, o b) => k a b -> ConstrainedCategory k o a b+constrained = ConstrainedMorphism++-- | \"Unpack\" a constrained morphism again (forgetful functor).+-- +-- Note that you may often not need to do that; in particular+-- morphisms that are actually 'Function's can just be applied+-- to their objects with '$' right away, no need to go back to+-- Hask first.+unconstrained :: (Category k) => ConstrainedCategory k o a b -> k a b+unconstrained = unconstrainedMorphism++instance (Category k) => Category (ConstrainedCategory k isObj) where+ type Object (ConstrainedCategory k isObj) o = (Object k o, isObj o)+ id = ConstrainedMorphism id+ ConstrainedMorphism f . ConstrainedMorphism g = ConstrainedMorphism $ f . g+++-- | Apart from /the/ identity morphism, 'id', there are other morphisms that+-- can basically be considered identies. For instance, in any cartesian+-- category (where it makes sense to have tuples and unit @()@ at all), it should be+-- possible to switch between @a@ and the isomorphic @(a, ())@. 'iso' is+-- the method for such \"pseudo-identities\", the most basic of which+-- are required as methods of the 'Cartesian' class.+-- +-- Why it is necessary to make these morphisms explicit: they are needed+-- for a couple of general-purpose category-theory methods, but even though+-- they're normally trivial to define there is no uniform way to do so.+-- For instance, for vector spaces, the baseis of @(a, (b,c))@ and @((a,b), c)@+-- are sure enough structurally equivalent, but not in the same way the spaces+-- themselves are (sum vs. product types).+{-# DEPRECATED iso "This generic method, while looking nicely uniform, relies on OverlappingInstances and is therefore probably a bad idea. Use the specialised methods in classes like 'SPDistribute' instead." #-}+class (Category k) => Isomorphic k a b where+ iso :: k a b++instance (Cartesian k, Object k a, u ~ UnitObject k, ObjectPair k a u) => Isomorphic k a (a,u) where+ iso = attachUnit+instance (Cartesian k, Object k a, u ~ UnitObject k, ObjectPair k a u) => Isomorphic k (a,u) a where+ iso = detachUnit+instance (Cartesian k, Object k a, u ~ UnitObject k, ObjectPair k a u, ObjectPair k u a, Object k (u, a), Object k (a, u) ) + => Isomorphic k a (u,a) where+ iso = swap . attachUnit+instance (Cartesian k, Object k a, u ~ UnitObject k, ObjectPair k a u, ObjectPair k u a, Object k (u, a), Object k (a, u) ) + => Isomorphic k (u,a) a where+ iso = detachUnit . swap+instance ( Cartesian k, Object k a, ObjectPair k a b, ObjectPair k b c+ , ObjectPair k a (b,c), ObjectPair k (a,b) c, Object k c )+ => Isomorphic k (a,(b,c)) ((a,b),c) where+ iso = regroup+instance ( Cartesian k, Object k a, ObjectPair k a b, ObjectPair k b c+ , ObjectPair k a (b,c), ObjectPair k (a,b) c, Object k c )+ => Isomorphic k ((a,b),c) (a,(b,c)) where+ iso = regroup'+++instance (CoCartesian k, Object k a, u ~ ZeroObject k, ObjectSum k a u) => Isomorphic k a (a+u) where+ iso = attachZero+instance (CoCartesian k, Object k a, u ~ ZeroObject k, ObjectSum k a u) => Isomorphic k (a+u) a where+ iso = detachZero+instance (CoCartesian k, Object k a, u ~ ZeroObject k, ObjectSum k a u, ObjectSum k u a, Object k (u+a), Object k (a+u) ) + => Isomorphic k a (u+a) where+ iso = coSwap . attachZero+instance (CoCartesian k, Object k a, u ~ ZeroObject k, ObjectSum k a u, ObjectSum k u a, Object k (u+a), Object k (a+u) ) + => Isomorphic k (u+a) a where+ iso = detachZero . coSwap+instance ( CoCartesian k, Object k a, ObjectSum k a b, ObjectSum k b c+ , ObjectSum k a (b+c), ObjectSum k (a+b) c, Object k c )+ => Isomorphic k (a+(b+c)) ((a+b)+c) where+ iso = coRegroup+instance ( CoCartesian k, Object k a, ObjectSum k a b, ObjectSum k b c+ , ObjectSum k a (b+c), ObjectSum k (a+b) c, Object k c )+ => Isomorphic k ((a+b)+c) (a+(b+c)) where+ iso = coRegroup'+++-- | Quite a few categories (/monoidal categories/) will permit \"products\" of +-- objects as objects again – in the Haskell sense those are tuples – allowing+-- for \"dyadic morphisms\" @(x,y) ~> r@.+-- +-- Together with a unique 'UnitObject', this makes for a monoidal+-- structure, with a few natural isomorphisms. Ordinary tuples may not+-- always be powerful enough to express the product objects; we avoid+-- making a dedicated associated type for the sake of simplicity,+-- but allow for an extra constraint to be imposed on objects prior+-- to consideration of pair-building.+-- +-- The name 'Cartesian' is disputable: in category theory that would rather+-- Imply /cartesian closed category/ (which we represent with 'Curry').+-- 'Monoidal' would make sense, but we reserve that to 'Functors'.+class ( Category k+ , Monoid (UnitObject k), Object k (UnitObject k)+ -- , PairObject k (UnitObject k) (UnitObject k), Object k (UnitObject k,UnitObject k) + ) => Cartesian k where+ -- | Extra properties two types @a, b@ need to fulfill so @(a,b)@ can be an+ -- object of the category. This need /not/ take care for @a@ and @b@ themselves + -- being objects, we do that seperately: every function that actually deals+ -- with @(a,b)@ objects should require the stronger @'ObjectPair' k a b@.+ -- + -- If /any/ two object types of your category make up a pair object, then+ -- just leave 'PairObjects' at the default (empty constraint).+ type PairObjects k a b :: Constraint+ type PairObjects k a b = ()+ + -- | Defaults to '()', and should normally be left at that.+ type UnitObject k :: *+ type UnitObject k = ()+ + swap :: ( ObjectPair k a b, ObjectPair k b a ) => k (a,b) (b,a)+ + attachUnit :: ( Object k a, u ~ UnitObject k, ObjectPair k a u ) => k a (a,u)+ detachUnit :: ( Object k a, u ~ UnitObject k, ObjectPair k a u ) => k (a,u) a+ regroup :: ( Object k a, Object k c, ObjectPair k a b, ObjectPair k b c+ , ObjectPair k a (b,c), ObjectPair k (a,b) c+ ) => k (a, (b, c)) ((a, b), c)+ regroup' :: ( Object k a, Object k c, ObjectPair k a b, ObjectPair k b c+ , ObjectPair k a (b,c), ObjectPair k (a,b) c+ ) => k ((a, b), c) (a, (b, c))++-- | Use this constraint to ensure that @a@, @b@ and @(a,b)@ are all \"fully valid\" objects+-- of your category (meaning, you can use them with the 'Cartesian' combinators).+type ObjectPair k a b = ( Category k, Object k a, Object k b+ , PairObjects k a b, Object k (a,b) )++instance Cartesian (->) where+ swap = \(a,b) -> (b,a)+ attachUnit = \a -> (a, ())+ detachUnit = \(a, ()) -> a+ regroup = \(a, (b, c)) -> ((a, b), c)+ regroup' = \((a, b), c) -> (a, (b, c))+ +instance (Cartesian f, o (UnitObject f)) => Cartesian (ConstrainedCategory f o) where+ type PairObjects (ConstrainedCategory f o) a b = (PairObjects f a b)+ type UnitObject (ConstrainedCategory f o) = UnitObject f++ swap = ConstrainedMorphism swap+ attachUnit = ConstrainedMorphism attachUnit+ detachUnit = ConstrainedMorphism detachUnit+ regroup = ConstrainedMorphism regroup+ regroup' = ConstrainedMorphism regroup'+++type (+) = Either++-- | Monoidal categories need not be based on a cartesian product.+-- The relevant alternative is coproducts.+-- +-- The dual notion to 'Cartesian' replaces such products (pairs) with+-- sums ('Either'), and unit '()' with void types.+-- +-- Basically, the only thing that doesn't mirror 'Cartesian' here+-- is that we don't require @CoMonoid ('ZeroObject' k)@. Comonoids+-- do in principle make sense, but not from a Haskell viewpoint+-- (every type is trivially a comonoid).+-- +-- Haskell of course uses sum types, /variants/, most often without+-- 'Either' appearing. But variants are generally isomorphic to sums;+-- the most important (sums of unit) are methods here.+class ( Category k, Object k (ZeroObject k)+ ) => CoCartesian k where+ type SumObjects k a b :: Constraint+ type SumObjects k a b = ()+ -- | Defaults to 'Void'.+ type ZeroObject k :: *+ type ZeroObject k = Void+ + coSwap :: ( ObjectSum k a b, ObjectSum k b a ) => k (a+b) (b+a)+ + attachZero :: ( Object k a, z ~ ZeroObject k, ObjectSum k a z ) => k a (a+z)+ detachZero :: ( Object k a, z ~ ZeroObject k, ObjectSum k a z ) => k (a+z) a+ coRegroup :: ( Object k a, Object k c, ObjectSum k a b, ObjectSum k b c+ , ObjectSum k a (b+c), ObjectSum k (a+b) c+ ) => k (a+(b+c)) ((a+b)+c)+ coRegroup' :: ( Object k a, Object k c, ObjectSum k a b, ObjectSum k b c+ , ObjectSum k a (b+c), ObjectSum k (a+b) c+ ) => k ((a+b)+c) (a+(b+c))+ + maybeAsSum :: ( ObjectSum k u a, u ~ UnitObject k, Object k (Maybe a) )+ => k (Maybe a) (u + a)+ maybeFromSum :: ( ObjectSum k u a, u ~ UnitObject k, Object k (Maybe a) )+ => k (u + a) (Maybe a)+ boolAsSum :: ( ObjectSum k u u, u ~ UnitObject k, Object k Bool )+ => k Bool (u + u)+ boolFromSum :: ( ObjectSum k u u, u ~ UnitObject k, Object k Bool )+ => k (u + u) Bool++type ObjectSum k a b = ( Category k, Object k a, Object k b+ , SumObjects k a b, Object k (a+b) )+++instance CoCartesian (->) where+ coSwap (Left a) = Right a+ coSwap (Right a) = Left a+ attachZero = Left+ detachZero (Left a) = a+ detachZero (Right void) = absurd void+ coRegroup (Left a) = Left $ Left a+ coRegroup (Right (Left a)) = Left $ Right a+ coRegroup (Right (Right a)) = Right a+ coRegroup' (Left (Left a)) = Left a+ coRegroup' (Left (Right a)) = Right $ Left a+ coRegroup' (Right a) = Right $ Right a+ maybeAsSum Nothing = Left ()+ maybeAsSum (Just x) = Right x+ maybeFromSum (Left ()) = Nothing+ maybeFromSum (Right x) = Just x+ boolAsSum False = Left ()+ boolAsSum True = Right ()+ boolFromSum (Left ()) = False+ boolFromSum (Right ()) = True+-- boolAsSwitch (False,x) = Left x+-- boolAsSwitch (True,x) = Right x+-- boolFromSwitch (Left x) = (False,x)+-- boolFromSwitch (Right x) = (True,x)+-- +instance (CoCartesian f, o (ZeroObject f)) => CoCartesian (ConstrainedCategory f o) where+ type SumObjects (ConstrainedCategory f o) a b = (SumObjects f a b)+ type ZeroObject (ConstrainedCategory f o) = ZeroObject f++ coSwap = ConstrainedMorphism coSwap+ attachZero = ConstrainedMorphism attachZero+ detachZero = ConstrainedMorphism detachZero+ coRegroup = ConstrainedMorphism coRegroup+ coRegroup' = ConstrainedMorphism coRegroup'+ maybeAsSum = ConstrainedMorphism maybeAsSum+ maybeFromSum = ConstrainedMorphism maybeFromSum+ boolAsSum = ConstrainedMorphism boolAsSum+ boolFromSum = ConstrainedMorphism boolFromSum+-- boolAsSwitch = ConstrainedMorphism boolAsSwitch+-- boolFromSwitch = ConstrainedMorphism boolFromSwitch+ +++++-- | Tagged type for values that depend on some choice of category, but not on some+-- particular object / arrow therein.+type CatTagged k x = Tagged (k (UnitObject k) (UnitObject k)) x+ ++ + +class (Cartesian k) => Curry k where+ type MorphObjects k b c :: Constraint+ type MorphObjects k b c = ()+ uncurry :: (ObjectPair k a b, ObjectMorphism k b c)+ => k a (k b c) -> k (a, b) c+ -- uncurry f = apply . (f &&& id)+ curry :: (ObjectPair k a b, ObjectMorphism k b c) + => k (a, b) c -> k a (k b c)+ apply :: (ObjectMorphism k a b, ObjectPair k (k a b) a)+ => k (k a b, a) b+ apply = uncurry id++-- | Analogous to 'ObjectPair': express that @k b c@ be an exponential object+-- representing the morphism.+type ObjectMorphism k b c = (Object k b, Object k c, MorphObjects k b c, Object k (k b c))+ ++instance Curry (->) where+ uncurry = Prelude.uncurry+ curry = Prelude.curry+ apply (f,x) = f x+ ++instance (Curry f, o (UnitObject f)) => Curry (ConstrainedCategory f o) where+ type MorphObjects (ConstrainedCategory f o) a c = ( MorphObjects f a c, f ~ (->) )+ uncurry (ConstrainedMorphism f) = ConstrainedMorphism $ \(a,b) -> unconstrained (f a) b+ curry (ConstrainedMorphism f) = ConstrainedMorphism $ \a -> ConstrainedMorphism $ \b -> f (a, b)+ +++infixr 0 $~++-- | A proxy value is a \"general representation\" of a category's+-- values, i.e. /global elements/. This is useful to define certain+-- morphisms (including ones that can't just \"inherit\" from '->'+-- with 'Control.Arrow.Constrained.arr') in ways other than point-free+-- composition pipelines. Instead, you can write algebraic expressions+-- much as if dealing with actual values of your category's objects,+-- but using the proxy type which is restricted so any function+-- defined as such a lambda-expression qualifies as a morphism +-- of that category.+class (Category k) => HasProxy k where+ type ProxyVal k a v :: *+ type ProxyVal k a v = GenericProxy k a v+ alg :: ( Object k a, Object k b+ ) => (forall q . Object k q+ => ProxyVal k q a -> ProxyVal k q b) -> k a b+ ($~) :: ( Object k a, Object k b, Object k c + ) => k b c -> ProxyVal k a b -> ProxyVal k a c++data GenericProxy k a v = GenericProxy { runGenericProxy :: k a v }++genericAlg :: ( HasProxy k, Object k a, Object k b )+ => ( forall q . Object k q+ => GenericProxy k q a -> GenericProxy k q b ) -> k a b+genericAlg f = runGenericProxy . f $ GenericProxy id++genericProxyMap :: ( HasProxy k, Object k a, Object k b, Object k c )+ => k b c -> GenericProxy k a b -> GenericProxy k a c+genericProxyMap m (GenericProxy v) = GenericProxy $ m . v++++instance HasProxy (->) where+ type ProxyVal (->) a b = b+ alg f = f+ ($~) = ($)+++
+ Control/Category/Constrained/Prelude.hs view
@@ -0,0 +1,32 @@+-- |+-- Module : Control.Category.Constrained.Prelude+-- Copyright : (c) 2013 Justus Sagemüller+-- License : GPL v3 (see COPYING)+-- Maintainer : (@) sagemueller $ geo.uni-koeln.de+-- ++{-# LANGUAGE ConstraintKinds #-}+{-# LANGUAGE TypeFamilies #-}++module Control.Category.Constrained.Prelude ( + -- * The constrained-categories facilities+ module Control.Category.Constrained+ , module Control.Functor.Constrained+ , module Control.Applicative.Constrained+ , module Control.Monad.Constrained+ , module Control.Arrow.Constrained+ -- * The compatible part of the standard Prelude + , module Prelude+ ) where++import Prelude hiding ( id, const, fst, snd, (.), ($), curry, uncurry+ , Functor(..), Monad(..), (=<<), filter+ , mapM, mapM_, sequence, sequence_ )++import Control.Category.Constrained hiding (ConstrainedMorphism)+import Control.Functor.Constrained+import Control.Applicative.Constrained+import Control.Monad.Constrained hiding + (MonadPlus(..), MonadZero(..), (>=>), (<=<), guard, forever, void)+import Control.Arrow.Constrained (Function, ($), ifThenElse, fst, snd, const)+
+ Control/Category/Hask.hs view
@@ -0,0 +1,36 @@+-- |+-- Module : Control.Category.Hask+-- Copyright : (c) 2013 Justus Sagemüller+-- License : GPL v3 (see COPYING)+-- Maintainer : (@) sagemueller $ geo.uni-koeln.de+-- +-- Re-exports of all the common category-theory inspired classes from the+-- "base" package, i.e. basically endofunctors in the Hask category (with+-- functions @(->)@ as morphisms).+-- The module is thus intended to be imported @qualified as Hask@.+-- +-- Main use case would be defining new such functors / monads etc.+-- yourself; even if you only intend to use them through the more+-- general category-agnostic interface established in this package+-- then the /instances/ should still be defined for the plain old+-- Hask-specific classes, i.e. for some+-- +-- > data F a = ...+-- > fmapF :: (a->b) -> F a->F b@+-- >+-- > instance Hask.Functor F where+-- > Hask.fmap = fmapF+-- +-- An instance of 'Control.Functor.Constrained.Functor' arises automatically+-- from this, as defined generically for all @(->)@ functors in that+-- module.++module Control.Category.Hask( module Prelude+ , module Control.Category+ , module Control.Applicative+ , module Control.Monad + ) where+import Prelude hiding ((.), id)+import Control.Category+import Control.Applicative+import Control.Monad
+ Control/Functor/Constrained.hs view
@@ -0,0 +1,95 @@+-- |+-- Module : Control.Functor.Constrained+-- Copyright : (c) 2014 Justus Sagemüller+-- License : GPL v3 (see COPYING)+-- Maintainer : (@) sagemueller $ geo.uni-koeln.de+-- ++{-# LANGUAGE ConstraintKinds #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE FunctionalDependencies #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE UndecidableInstances #-}+++module Control.Functor.Constrained+ ( module Control.Category.Constrained+ -- * Functors+ , Functor(..)+ , (<$>)+ , constrainedFmap+ -- * [Co]product mapping+ , SumToProduct(..)+ ) where+++import Control.Category.Constrained++import Prelude hiding (id, (.), Functor(..), filter)+import qualified Prelude++import Data.Void++class ( Category r, Category t, Object t (f (UnitObject r)) )+ => Functor f r t | f r -> t, f t -> r where+ fmap :: (Object r a, Object t (f a), Object r b, Object t (f b))+ => r a b -> t (f a) (f b)++instance (Prelude.Functor f) => Functor f (->) (->) where+ fmap = Prelude.fmap++-- | It is fairly common for functors (typically, container-like) to map 'Either'+-- to tuples in a natural way, thus \"separating the variants\".+-- This is related to 'Data.Foldable.Constrained.Foldable'+-- (with list and tuple monoids), but rather more effective.+class ( CoCartesian r, Cartesian t, Functor f r t, Object t (f (ZeroObject r)) )+ => SumToProduct f r t where+ -- | @+ -- sum2product ≡ mapEither id+ -- @+ sum2product :: ( ObjectSum r a b, ObjectPair t (f a) (f b) )+ => t (f (a+b)) (f a, f b)+ -- | @+ -- mapEither f ≡ sum2product . fmap f+ -- @+ mapEither :: ( Object r a, ObjectSum r b c+ , Object t (f a), ObjectPair t (f b) (f c) )+ => r a (b+c) -> t (f a) (f b, f c)+ filter :: ( Object r a, Object r Bool, Object t (f a) )+ => r a Bool -> t (f a) (f a)++instance SumToProduct [] (->) (->) where+ sum2product [] = ([],[])+ sum2product (Left x : l) = (x:xs, ys) where ~(xs,ys) = sum2product l+ sum2product (Right y : l) = (xs ,y:ys) where ~(xs,ys) = sum2product l+ mapEither _ [] = ([],[])+ mapEither f (a:l) = case f a of+ Left x -> (x:xs, ys)+ Right y -> (xs ,y:ys)+ where ~(xs,ys) = mapEither f l+ filter = Prelude.filter++(<$>) :: (Functor f r (->), Object r a, Object r b)+ => r a b -> f a -> f b+(<$>) = fmap++ +constrainedFmap :: (Category r, Category t, o a, o b, o (f a), o (f b)) + => ( r a b -> t (f a) (f b) ) + -> ConstrainedCategory r o a b -> ConstrainedCategory t o (f a) (f b)+constrainedFmap q = constrained . q . unconstrained++instance (Functor [] k k, o [UnitObject k]) + => Functor [] (ConstrainedCategory k o) (ConstrainedCategory k o) where+ fmap (ConstrainedMorphism f) = ConstrainedMorphism $ fmap f++instance (o (), o [()], o Void, o [Void]) => SumToProduct []+ (ConstrainedCategory (->) o) (ConstrainedCategory (->) o) where+ sum2product = ConstrainedMorphism sum2product+ mapEither (ConstrainedMorphism f) = ConstrainedMorphism $ mapEither f+ filter (ConstrainedMorphism f) = ConstrainedMorphism $ filter f++ +
+ Control/Monad/Constrained.hs view
@@ -0,0 +1,274 @@+-- |+-- Module : Control.Monad.Constrained+-- Copyright : (c) 2013 Justus Sagemüller+-- License : GPL v3 (see COPYING)+-- Maintainer : (@) sagemueller $ geo.uni-koeln.de+-- +{-# LANGUAGE ConstraintKinds #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE FunctionalDependencies #-}+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TupleSections #-}+{-# LANGUAGE LambdaCase #-}+++module Control.Monad.Constrained( module Control.Applicative.Constrained + -- * Monads + , Monad(..), return, (>>=), (=<<), (>>), (<<)+ -- * Kleisli arrows+ , (>=>), (<=<)+ , Kleisli(..)+ -- * Monoid-Monads+ , MonadZero(..), mzero, MonadPlus(..), mplus+ , MonadFail(..)+ -- * Utility+ , mapM, mapM_, forM, forM_, sequence, sequence_+ , guard, when, unless+ , forever, void+ ) where+++import Control.Applicative.Constrained+import Data.Foldable.Constrained+import Data.Traversable.Constrained+import Data.Tagged++import Prelude hiding (+ id, const, fst, snd, (.), ($)+ , Functor(..), Monad(..), (=<<)+ , uncurry, curry+ , mapM, mapM_, sequence, sequence_+ )+import qualified Control.Category.Hask as Hask++import Control.Arrow.Constrained+++class ( Applicative m k k+ , Object k (m (UnitObject k)), Object k (m (m (UnitObject k)))+ ) => Monad m k where+ join :: (Object k a, Object k (m a), Object k (m (m a)))+ => m (m a) `k` m a++-- | This is monomorphic in the category /Hask/, thus exactly the same as 'Hask.return'+-- from the standard prelude. This allows writing expressions like+-- @'return' '$' case x of ...@, which would always be ambiguous with the more general +-- signature @Monad m k => k a (m a)@.+-- +-- Use 'pure' when you want to \"return\" in categories other than @(->)@; this always+-- works since 'Applicative' is a superclass of 'Monad'.+return :: Monad m (->) => a -> m a+return = pure++ ++infixr 1 =<<+(=<<) :: ( Monad m k, Object k a, Object k b+ , Object k (m a), Object k (m b), Object k (m (m b)) )+ => k a (m b) -> k (m a) (m b)+(=<<) q = join . fmap q++infixl 1 >>=+(>>=) :: ( Function f, Monad m f, Object f a, Object f b+ , Object f (m a), Object f (m b), Object f (m (m b)) ) + => m a -> f a (m b) -> m b+g >>= h = (=<<) h $ g++infixr 1 <<+(<<) :: ( Monad m k, WellPointed k+ , Object k a, Object k b, Object k (m a), ObjectPoint k (m b), Object k (m (m b))+ ) => m b -> k (m a) (m b)+(<<) b = join . fmap (const b)++infixl 1 >>+(>>) :: ( WellPointed k, Monad m k+ , ObjectPair k b (UnitObject k), ObjectPair k (m b) (UnitObject k)+ , ObjectPair k (UnitObject k) (m b), ObjectPair k b a+ , ObjectPair k a b, Object k (m (a,b)), ObjectPair k (m a) (m b)+ , ObjectPoint k (m a)+ ) => m a -> k (m b) (m b)+(>>) a = fmap snd . fzip . first (globalElement a) . swap . attachUnit+ -- where result = arr $ \b -> (join . fmap (const b)) `inCategoryOf` result $ a+++instance (Hask.Applicative m, Hask.Monad m) => Monad m (->) where+ join = Hask.join+ ++-- | 'Hask.MonadPlus' cannot be adapted quite analogously to 'Monad',+-- since 'mzero' is just a value with no way to indicate its morphism+-- category. The current implementation is probably not ideal, mainly+-- written to give 'MonadFail' ('fail' being needed for @RebindableSyntax@-@do@+-- notation) a mathematically reasonable superclass.+-- +-- Consider these classes provisorial, avoid relying on them explicitly.+class (Monad m k) => MonadZero m k where+ fmzero :: (Object k a, Object k (m a)) => UnitObject k `k` m a++mzero :: (MonadZero m (->)) => m a+mzero = fmzero ()++class (MonadZero m k) => MonadPlus m k where+ fmplus :: (ObjectPair k (m a) (m a)) => k (m a, m a) (m a)++mplus :: (MonadPlus m (->)) => m a -> m a -> m a+mplus = curry fmplus+ +instance (Hask.MonadPlus m, Hask.Applicative m) => MonadZero m (->) where+ fmzero = const Hask.mzero+instance (Hask.MonadPlus m, Hask.Applicative m) => MonadPlus m (->) where+ fmplus = uncurry Hask.mplus+++class (MonadPlus m k) => MonadFail m k where+ fail :: (Object k (m a)) => k String (m a) ++instance (Hask.MonadPlus m, Hask.Applicative m) => MonadFail m (->) where+ fail = Hask.fail+ ++infixr 1 >=>, <=<++(>=>) :: ( Monad m k, Object k a, Object k b, Object k c+ , Object k (m b), Object k (m c), Object k (m (m c)))+ => a `k` m b -> b `k` m c -> a `k` m c+f >=> g = join . fmap g . f+(<=<) :: ( Monad m k, Object k a, Object k b, Object k c+ , Object k (m b), Object k (m c), Object k (m (m c)))+ => b `k` m c -> a `k` m b -> a `k` m c+f <=< g = join . fmap f . g++newtype Kleisli m k a b = Kleisli { runKleisli :: k a (m b) }++instance (Monad m k) => Category (Kleisli m k) where+ type Object (Kleisli m k) o = (Object k o, Object k (m o), Object k (m (m o)))+ id = Kleisli pure+ Kleisli a . Kleisli b = Kleisli $ join . fmap a . b++instance ( Monad m a, Cartesian a ) => Cartesian (Kleisli m a) where+ type PairObjects (Kleisli m a) b c + = ( ObjectPair a b c+ , ObjectPair a (m b) c, ObjectPair a b (m c), ObjectPair a (m b) (m c) )+ type UnitObject (Kleisli m a) = UnitObject a+ swap = Kleisli $ pure . swap+ attachUnit = Kleisli $ pure . attachUnit+ detachUnit = Kleisli $ pure . detachUnit+ regroup = Kleisli $ pure . regroup+ regroup' = Kleisli $ pure . regroup'++instance ( Monad m k, CoCartesian k+ , Object k (m (ZeroObject k)), Object k (m (m (ZeroObject k)))+ ) => CoCartesian (Kleisli m k) where+ type SumObjects (Kleisli m k) b c + = ( ObjectSum k b c+ , ObjectSum k (m b) c, ObjectSum k b (m c), ObjectSum k (m b) (m c) )+ type ZeroObject (Kleisli m k) = ZeroObject k+ coSwap = Kleisli $ pure . coSwap+ attachZero = Kleisli $ pure . attachZero+ detachZero = Kleisli $ pure . detachZero+ coRegroup = Kleisli $ pure . coRegroup+ coRegroup' = Kleisli $ pure . coRegroup'+ + maybeAsSum = Kleisli $ pure . maybeAsSum+ maybeFromSum = Kleisli $ pure . maybeFromSum+ boolAsSum = Kleisli $ pure . boolAsSum+ boolFromSum = Kleisli $ pure . boolFromSum+ +instance ( Monad m a, Arrow a (->), Function a ) => Curry (Kleisli m a) where+ type MorphObjects (Kleisli m a) c d+ = ( Object a (Kleisli m a c d), Object a (m (Kleisli m a c d))+ , Object a (a c (m d))+ , ObjectMorphism a c d, ObjectMorphism a c (m d), ObjectMorphism a c (m (m d)) )+ curry (Kleisli fUnc) = Kleisli $ pure . arr Kleisli . curry fUnc+ uncurry (Kleisli fCur) = Kleisli . arr $ + \(b,c) -> join . fmap (arr $ ($c) . runKleisli) . fCur $ b+ ++ ++instance (Monad m a, Arrow a q, Cartesian a) => EnhancedCat (Kleisli m a) q where+ arr f = Kleisli $ pure . arr f+instance (Monad m a, Morphism a, Curry a) => Morphism (Kleisli m a) where+ first (Kleisli f) = Kleisli $ fzip . (f *** pure)+ second (Kleisli f) = Kleisli $ fzip . (pure *** f)+ Kleisli f *** Kleisli g = Kleisli $ fzip . (f *** g)+instance (Monad m a, PreArrow a, Curry a) => PreArrow (Kleisli m a) where+ Kleisli f &&& Kleisli g = Kleisli $ fzip . (f &&& g)+ terminal = Kleisli $ pure . terminal+ fst = Kleisli $ pure . fst+ snd = Kleisli $ pure . snd+instance (SPDistribute k, Monad m k, PreArrow (Kleisli m k), PreArrChoice (Kleisli m k)) + => SPDistribute (Kleisli m k) where+ distribute = Kleisli $ pure . distribute+ unDistribute = Kleisli $ pure . unDistribute+ boolAsSwitch = Kleisli $ pure . boolAsSwitch+ boolFromSwitch = Kleisli $ pure . boolFromSwitch+instance (Monad m a, WellPointed a, ObjectPoint a (m (UnitObject a))) + => WellPointed (Kleisli m a) where+ type PointObject (Kleisli m a) b = (PointObject a b, PointObject a (m b))+ globalElement x = Kleisli $ fmap (globalElement x) . pureUnit+ unit = kleisliUnit+++-- | /Hask/-Kleislis inherit more or less trivially 'Hask.ArrowChoice'; however this+-- does not generalise greatly well to non-function categories.+instance ( Monad m k, Arrow k (->), Function k, PreArrChoice k+ , Object k (m (ZeroObject k)), Object k (m (m (ZeroObject k)))+ ) => MorphChoice (Kleisli m k) where+ left (Kleisli f) = Kleisli . arr $ \case { Left x -> fmap coFst . f $ x+ ; Right y-> (pure . coSnd)`inCategoryOf`f $ y }+ right(Kleisli f) = Kleisli . arr $ \case { Left x -> (pure . coFst)`inCategoryOf`f $ x+ ; Right y-> fmap coSnd . f $ y }+ Kleisli f +++ Kleisli g = Kleisli . arr $ \case+ Left x -> fmap coFst . f $ x+ Right y -> fmap coSnd . g $ y+instance ( Monad m k, Arrow k (->), Function k, PreArrChoice k+ , Object k (m (ZeroObject k)), Object k (m (m (ZeroObject k)))+ ) => PreArrChoice (Kleisli m k) where+ Kleisli f ||| Kleisli g = Kleisli $ f ||| g+ initial = Kleisli $ pure . initial+ coFst = Kleisli $ pure . coFst+ coSnd = Kleisli $ pure . coSnd+++kleisliUnit :: forall m a . (Monad m a, WellPointed a)+ => CatTagged (Kleisli m a) (UnitObject a)+kleisliUnit = retag (unit :: CatTagged a (UnitObject a))+++guard ::( MonadPlus m k, Arrow k (->), Function k+ , UnitObject k ~ (), Object k Bool+ ) => Bool `k` m ()+guard = i . choose fmzero pure+ where i = id+++when :: ( Monad m k, PreArrow k, u ~ UnitObject k+ , ObjectPair k (m u) u+ ) => Bool -> m u `k` m u+when True = id+when False = pure . terminal+unless :: ( Monad m k, PreArrow k, u ~ UnitObject k+ , ObjectPair k (m u) u+ ) => Bool -> m u `k` m u+unless False = id+unless True = pure . terminal+ +++forever :: ( Monad m k, Function k, Arrow k (->), Object k a, Object k b + , Object k (m a), Object k (m (m a)), ObjectPoint k (m b), Object k (m (m b))+ ) => m a `k` m b+forever = i . arr loop + where loop a = (join . fmap (const $ loop a)) `inCategoryOf` i $ a+ i = id++void :: ( Monad m k, PreArrow k+ , Object k a, Object k (m a), ObjectPair k a u, u ~ UnitObject k + ) => m a `k` m (UnitObject k)+void = fmap terminal+ +
+ Data/Foldable/Constrained.hs view
@@ -0,0 +1,166 @@+-- |+-- Module : Data.Foldable.Constrained+-- Copyright : (c) 2014 Justus Sagemüller+-- License : GPL v3 (see COPYING)+-- Maintainer : (@) sagemueller $ geo.uni-koeln.de+-- +{-# LANGUAGE ConstraintKinds #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE FunctionalDependencies #-}+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE KindSignatures #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TupleSections #-}+++module Data.Foldable.Constrained+ ( module Control.Category.Constrained + , Foldable(..)+ , fold+ , traverse_, mapM_, forM_, sequence_+ , concatMap+ ) where+++import Control.Category.Constrained+import Control.Functor.Constrained+import Control.Applicative.Constrained++import Prelude hiding (+ id, (.), ($)+ , Functor(..)+ , uncurry, curry+ , mapM_, sequence_, concatMap+ )+import Data.Monoid++import qualified Control.Category.Hask as Hask+import qualified Control.Arrow as A++import Control.Arrow.Constrained+++++class (Functor t k l) => Foldable t k l where+ ffoldl :: ( ObjectPair k a b, ObjectPair l a (t b)+ ) => k (a,b) a -> l (a,t b) a+ foldMap :: ( Object k a, Object l (t a), Monoid m, Object k m, Object l m )+ => (a `k` m) -> t a `l` m++fold :: (Foldable t k k, Monoid m, Object k m, Object k (t m)) => t m `k` m+fold = foldMap id++newtype Endo' k a = Endo' { runEndo' :: k a a }+instance (Category k, Object k a) => Monoid (Endo' k a) where+ mempty = Endo' id+ mappend (Endo' f) (Endo' g) = Endo' $ f . g++newtype Monoidal_ (r :: * -> * -> *) (s :: * -> * -> *) (f :: * -> *) (u :: *) + = Monoidal { runMonoidal :: f u }+instance ( Monoidal f k k, Function k+ , u ~ UnitObject k, Monoid u + , ObjectPair k u u, ObjectPair k (f u) (f u), Object k (f u,f u)+ ) => Monoid (Monoidal_ k k f u) where+ mempty = memptyMdl+ mappend = mappendMdl++memptyMdl :: forall r s f u v . ( Monoidal f r s, Function s+ , ObjectPair s u u, Monoid v+ , u~UnitObject r, v~UnitObject s )+ => Monoidal_ r s f u+memptyMdl = Monoidal ((pureUnit :: s v (f u)) $ mempty)+mappendMdl :: forall r s f u v . ( Monoidal f r s, Function s+ , ObjectPair r u u, ObjectPair s (f u) (f u)+ , Object s (f u, f u), Monoid v+ , u~UnitObject r, v~UnitObject s )+ => Monoidal_ r s f u -> Monoidal_ r s f u -> Monoidal_ r s f u+mappendMdl (Monoidal x) (Monoidal y) + = Monoidal (combine $ (x, y))+ where combine :: s (f u, f u) (f u)+ combine = fzipWith detachUnit++++instance Foldable [] (->) (->) where+ foldMap _ [] = mempty+ foldMap f (x:xs) = f x <> foldMap f xs+ ffoldl f = uncurry $ foldl (curry f)++instance Foldable Maybe (->) (->) where+ foldMap f Nothing = mempty+ foldMap f (Just x) = f x+ ffoldl _ (i,Nothing) = i+ ffoldl f (i,Just a) = f(i,a)+++instance ( Foldable f s t, WellPointed s, WellPointed t+ , Functor f (ConstrainedCategory s o) (ConstrainedCategory t o) + ) => Foldable f (ConstrainedCategory s o) (ConstrainedCategory t o) where+ foldMap (ConstrainedMorphism f) = ConstrainedMorphism $ foldMap f+ ffoldl (ConstrainedMorphism f) = ConstrainedMorphism $ ffoldl f++-- | Despite the ridiculous-looking signature, this is in fact equivalent+-- to 'Data.Foldable.traverse_' within Hask.+traverse_ :: forall t k l o f a b uk ul .+ ( Foldable t k l, PreArrow k, PreArrow l+ , Monoidal f l l, Monoidal f k k+ , ObjectPair l (f ul) (t a), ObjectPair k (f ul) a+ , ObjectPair l ul (t a), ObjectPair l (t a) ul+ , ObjectPair k b ul, Object k (f b)+ , ObjectPair k (f ul) (f ul), ObjectPair k ul ul+ , uk ~ UnitObject k, ul ~ UnitObject l, uk ~ ul+ ) => a `k` f b -> t a `l` f ul+traverse_ f = ffoldl q . first pureUnit . swap . attachUnit+ where q :: k (f uk, a) (f uk)+ q = fzipWith detachUnit . second (fmap terminal . f)+ +-- | The distinction between 'mapM_' and 'traverse_' doesn't really make sense+-- on grounds of 'Monoidal' / 'Applicative' vs 'Monad', but it has in fact some+-- benefits to restrict this to endofunctors, to make the constraint list+-- at least somewhat shorter.+mapM_ :: forall t k o f a b u .+ ( Foldable t k k, WellPointed k, Monoidal f k k+ , u ~ UnitObject k+ , ObjectPair k (f u) (t a), ObjectPair k (f u) a+ , ObjectPair k u (t a), ObjectPair k (t a) u+ , ObjectPair k (f u) (f u), ObjectPair k u u+ , ObjectPair k b u, Object k (f b)+ ) => a `k` f b -> t a `k` f u+mapM_ = traverse_+ +++forM_ :: forall t k l f a b uk ul .+ ( Foldable t k l, Monoidal f l l, Monoidal f k k+ , Function l, Arrow k (->), Arrow l (->), ul ~ UnitObject l+ , uk ~ UnitObject k, uk ~ ul+ , ObjectPair l ul ul, ObjectPair l (f ul) (f ul)+ , ObjectPair l (f ul) (t a), ObjectPair l ul (t a)+ , ObjectPair l (t a) ul, ObjectPair l (f ul) a+ , ObjectPair k b (f b), ObjectPair k b ul+ , ObjectPair k uk uk, ObjectPair k (f uk) a, ObjectPair k (f uk) (f uk)+ ) => t a -> a `k` f b -> f uk+forM_ v f = traverse_ f $ v+++sequence_ :: forall t k l m a b uk ul . + ( Foldable t k l, Arrow k (->), Arrow l (->)+ , uk ~ UnitObject k, ul ~ UnitObject l, uk ~ ul+ , Monoidal m k k, Monoidal m l l+ , ObjectPair k a uk, ObjectPair k (t (m a)) uk+ , ObjectPair k uk uk, ObjectPair k (m uk) (m uk), ObjectPair k (t (m a)) ul+ , ObjectPair l (m ul) (t (m a)), ObjectPair l ul (t (m a))+ , ObjectPair l (m uk) (t (m a)), ObjectPair l (t (m a)) ul+ , ObjectPair k (m uk) (m a)+ ) => t (m a) `l` m uk+sequence_ = traverse_ id ++++concatMap :: (Foldable f k l, Object k a, Object k [b], Object l (f a), Object l [b])+ => a `k` [b] -> f a `l` [b]+concatMap = foldMap+
+ Data/Traversable/Constrained.hs view
@@ -0,0 +1,91 @@+-- |+-- Module : Data.Traversable.Constrained+-- Copyright : (c) 2014 Justus Sagemüller+-- License : GPL v3 (see COPYING)+-- Maintainer : (@) sagemueller $ geo.uni-koeln.de+-- +{-# LANGUAGE ConstraintKinds #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE FunctionalDependencies #-}+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TupleSections #-}+++module Data.Traversable.Constrained+ ( module Control.Applicative.Constrained + , Traversable(..)+ , sequence, mapM, forM+ ) where+++import Control.Category.Constrained+import Control.Applicative.Constrained++import Prelude hiding (+ id, const, (.), ($)+ , Functor(..)+ , uncurry, curry+ , mapM, mapM_, sequence+ )+import qualified Control.Category.Hask as Hask+import qualified Control.Arrow as A++import Control.Arrow.Constrained++import Data.Monoid+++++class (Category k, Category l, Functor s l l, Functor t k k) + => Traversable s t k l | s k l -> t, t k l -> s, s t k -> l, s t l -> k where+ traverse :: ( Monoidal f k l, Object l a, Object l (s a)+ , ObjectPair k b (t b), ObjectPair l (f b) (f (t b)) + , ObjectPoint k (t b)+ ) => a `l` f b -> s a `l` f (t b)++sequence :: ( Traversable t t k k, Monoidal f k k+ , ObjectPair k a (t a), ObjectPair k (f a) (f (t a))+ , Object k (t (f a))+ , ObjectPoint k (t a)+ ) => t (f a) `k` f (t a)+sequence = traverse id++instance (Arrow k (->), WellPointed k, Function k, Functor [] k k) + => Traversable [] [] k k where+ traverse f = arr mM+ where mM [] = constPure [] `inCategoryOf` f $ mempty+ mM (x:xs) = fzipWith (arr $ uncurry(:)) `inCategoryOf` f + $ (f $ x, mM xs)++instance (Arrow k (->), WellPointed k, Function k, Functor Maybe k k)+ => Traversable Maybe Maybe k k where+ traverse f = arr mM + where mM Nothing = constPure Nothing `inCategoryOf` f $ mempty+ mM (Just x) = fmap (arr Just) . f $ x++-- data Stupid a = Stupid a+-- instance Functor Stupid (ConstrainedCategory (->) Num) (->) where+-- fmap (Stupid (ConstrainedMorphism f)) (Stupid a) = Stupid (f a)+-- ++-- | 'traverse', restricted to endofunctors.+mapM :: ( Traversable t t k k, Monoidal m k k+ , Object k a, Object k (t a), ObjectPair k b (t b), ObjectPair k (m b) (m (t b))+ , ObjectPoint k (t b)+ ) => a `k` m b -> t a `k` m (t b)+mapM = traverse++-- | Flipped version of 'traverse' / 'mapM'.+forM :: forall s t k m a b l . + ( Traversable s t k l, Monoidal m k l, Function l+ , Object k b, Object k (t b), ObjectPair k b (t b)+ , Object l a, Object l (s a), ObjectPair l (m b) (m (t b))+ , ObjectPoint k (t b)+ ) => s a -> (a `l` m b) -> m (t b)+forM v f = traverse f $ v++
+ Setup.hs view
@@ -0,0 +1,6 @@+module Main (main) where++import Distribution.Simple++main :: IO ()+main = defaultMain
+ constrained-categories.cabal view
@@ -0,0 +1,58 @@+Name: constrained-categories+Version: 0.1.0.0+Category: control+Synopsis: Constrained clones of the category-theory type classes, using ConstraintKinds.+Description: Haskell has, and makes great use of, powerful facilities from category+ theory – basically various variants of functors.+ .+ However, all those are just endofunctors in Hask, the category of+ all Haskell types with functions as morphisms. Which is sufficient+ for container / control structures that you want to be able to handle + any type of data, but otherwise it's a bit limiting, seeing as + there are (in maths, science etc.) many categories that cannot properly+ be represented this way. Commonly used libraries such as + <http://hackage.haskell.org/package/vector-space> thus make + little notion of the fact that the objects they deal with actually+ form a category, instead defining just specialised versions of+ the operations.+ .+ This library generalises functors etc. to a much wider class of+ categories, by allowing for constraints on objects (so these can have+ extra properties required). At the same time, we try to keep as close+ as possible to the well-known Haskell type class hierarchies rather+ than exactly adopting the mathematicians' notions.+ .+ Consider the README file, the examples, and/or the documentation to+ "Control.Category.Constrained" for how to make use of this.+License: GPL-3+License-file: COPYING+Author: Justus Sagemüller+Maintainer: (@) sagemuej $ smail.uni-koeln.de+Homepage: https://github.com/leftaroundabout/constrained-categories+Build-Type: Simple+Cabal-Version: >=1.10++source-repository head+ type: git+ location: git://github.com/leftaroundabout/constrained-categories.git++Library+ Default-Language: Haskell2010+ Build-Depends: base>=4.6 && <5+ , tagged+ , void+ Default-Extensions: ConstraintKinds+ TypeFamilies+ FlexibleInstances+ UndecidableInstances+ Trustworthy+ Exposed-modules: Control.Category.Constrained+ Control.Functor.Constrained+ Control.Applicative.Constrained+ Control.Arrow.Constrained+ Control.Monad.Constrained+ Control.Category.Hask+ Control.Category.Constrained.Prelude+ Data.Foldable.Constrained+ Data.Traversable.Constrained+