polysemy-scoped-fs (empty) → 0.1.0.0
raw patch · 25 files changed
+2395/−0 lines, 25 filesdep +basedep +bytestringdep +directorysetup-changed
Dependencies added: base, bytestring, directory, doctest, extra, path, polysemy, polysemy-fs, polysemy-path, polysemy-plugin, polysemy-scoped-fs, text
Files
- ChangeLog.adoc +3/−0
- ChangeLog.md +3/−0
- LICENSE +682/−0
- README.adoc +81/−0
- README.md +83/−0
- Setup.hs +2/−0
- polysemy-scoped-fs.cabal +125/−0
- src/Polysemy/Env.hs +26/−0
- src/Polysemy/FS/Scoped.hs +108/−0
- src/Polysemy/FS/Scoped/ByteString.hs +59/−0
- src/Polysemy/FS/Scoped/ByteString/Internal.hs +51/−0
- src/Polysemy/FS/Scoped/Internal.hs +152/−0
- src/Polysemy/FS/Scoped/Internal/MembersProof.hs +34/−0
- src/Polysemy/FS/Scoped/Oneshot.hs +158/−0
- src/Polysemy/FS/Scoped/Text.hs +87/−0
- src/Polysemy/FS/Scoped/Text/Internal.hs +70/−0
- src/Polysemy/Scoped/Path.hs +168/−0
- src/Polysemy/Scoped/Path/Internal.hs +128/−0
- src/Polysemy/Scoped/Path/Isolation.hs +63/−0
- src/Polysemy/ScopedReader.hs +91/−0
- src/Polysemy/SequentialAccess.hs +122/−0
- src/Polysemy/SequentialAccess/ByteString.hs +29/−0
- src/Polysemy/SequentialAccess/Text.hs +37/−0
- test/Spec.hs +2/−0
- test/doctests.hs +31/−0
+ ChangeLog.adoc view
@@ -0,0 +1,3 @@+= Changelog for polysemy-scoped-fs++== Unreleased changes
+ ChangeLog.md view
@@ -0,0 +1,3 @@+# Changelog for polysemy-scoped-fs++## Unreleased changes
+ LICENSE view
@@ -0,0 +1,682 @@+Copyright (C) 2022 Hisaket VioletRed++This package is mainly licensed under 'AGPL-3.0-or-later'. However,+only the below files partially contain source codes that are licensed+under 'AGPL-3.0-or-later AND BSD-...'. Please see the header comments+in these files for the details. These files also include the copyright+notice, the conditions, and the disclaimer related to the BSD license.++* src/Polysemy/Scoped/Path.hs+* src/Polysemy/Scoped/Path/Internal.hs+* src/Polysemy/FS/Scoped/Internal.hs+++Submission of Contributions+ Unless You explicitly state otherwise, any Contribution intentionally+ submitted for inclusion in the Work by You to the Licensor shall be+ under the terms and conditions of AGPL-3.0-or-later, without any+ additional terms or conditions; where Contribution, Work, You, and+ Licensor are as defined in the Apache-2.0 license.+++ GNU AFFERO GENERAL PUBLIC LICENSE+ Version 3, 19 November 2007++ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>+ Everyone is permitted to copy and distribute verbatim copies+ of this license document, but changing it is not allowed.++ Preamble++ The GNU Affero General Public License is a free, copyleft license for+software and other kinds of works, specifically designed to ensure+cooperation with the community in the case of network server software.++ The licenses for most software and other practical works are designed+to take away your freedom to share and change the works. By contrast,+our General Public Licenses are 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.++ 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.++ Developers that use our General Public Licenses protect your rights+with two steps: (1) assert copyright on the software, and (2) offer+you this License which gives you legal permission to copy, distribute+and/or modify the software.++ A secondary benefit of defending all users' freedom is that+improvements made in alternate versions of the program, if they+receive widespread use, become available for other developers to+incorporate. Many developers of free software are heartened and+encouraged by the resulting cooperation. However, in the case of+software used on network servers, this result may fail to come about.+The GNU General Public License permits making a modified version and+letting the public access it on a server without ever releasing its+source code to the public.++ The GNU Affero General Public License is designed specifically to+ensure that, in such cases, the modified source code becomes available+to the community. It requires the operator of a network server to+provide the source code of the modified version running there to the+users of that server. Therefore, public use of a modified version, on+a publicly accessible server, gives the public access to the source+code of the modified version.++ An older license, called the Affero General Public License and+published by Affero, was designed to accomplish similar goals. This is+a different license, not a version of the Affero GPL, but Affero has+released a new version of the Affero GPL which permits relicensing under+this license.++ 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 Affero 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. Remote Network Interaction; Use with the GNU General Public License.++ Notwithstanding any other provision of this License, if you modify the+Program, your modified version must prominently offer all users+interacting with it remotely through a computer network (if your version+supports such interaction) an opportunity to receive the Corresponding+Source of your version by providing access to the Corresponding Source+from a network server at no charge, through some standard or customary+means of facilitating copying of software. This Corresponding Source+shall include the Corresponding Source for any work covered by version 3+of the GNU General Public License that is incorporated pursuant to the+following paragraph.++ 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 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 work with which it is combined will remain governed by version+3 of the GNU General Public License.++ 14. Revised Versions of this License.++ The Free Software Foundation may publish revised and/or new versions of+the GNU Affero 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 Affero 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 Affero 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 Affero 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 Affero 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 Affero General Public License for more details.++ You should have received a copy of the GNU Affero General Public License+ along with this program. If not, see <https://www.gnu.org/licenses/>.++Also add information on how to contact you by electronic and paper mail.++ If your software can interact with users remotely through a computer+network, you should also make sure that it provides a way for users to+get its source. For example, if your program is a web application, its+interface could display a "Source" link that leads users to an archive+of the code. There are many ways you could offer source, and different+solutions will be better for different programs; see section 13 for the+specific requirements.++ 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 AGPL, see+<https://www.gnu.org/licenses/>.
+ README.adoc view
@@ -0,0 +1,81 @@+= polysemy-scoped-fs+:source-highlighter: highlight.js+:highlightjs-languages: haskell++This package provides well-typed (scoped) filesystem operation effects.+This is based on the idea and codes of https://www.tweag.io/blog/2022-01-05-polysemy-scoped/[Scoped Effect Resources for Polysemy] by Torsten Schmits.++== Example++We assume that the language extensions related to polysemy and polysemy-plugin are enabled.+cf. https://hackage.haskell.org/package/polysemy-1.7.1.0#readme++[source,haskell]+----+{-# LANGUAGE OverloadedStrings #-}++import qualified Polysemy.SequentialAccess as SA+import Polysemy (runFinal, embedToFinal, embed)+import Polysemy.Resource (resourceToIOFinal)+import Polysemy.Path+import Polysemy.FS.Scoped (scopedFile, AccessMode(RwAccess, ReadAccess))+import Polysemy.FS.Scoped.Text (rwAccessToIO, readAccessToIO)++writeFoobar :: IO ()+writeFoobar =+ runFinal $ embedToFinal $ resourceToIOFinal $ rwAccessToIO $ readAccessToIO $ do+ -- Open the file '/tmp/polysemy-scoped-fs-test' with read & write access mode.+ scopedFile @RwAccess [absfile|/tmp/polysemy-scoped-fs-test|] $ do+ SA.extend "This text will be deleted."+ SA.resize SA.NullSize -- Clear the file.+ SA.extend "foo" -- Append the text to the file.+ SA.extend "bar"+ SA.seek SA.TOF -- Seek to the top of the file.+ embed . print =<< SA.read SA.ToEnd++ -- Open the file with read only access mode.+ scopedFile @ReadAccess [absfile|/tmp/polysemy-scoped-fs-test|] $ do+ embed . print =<< SA.read SA.ToEnd++ -- SA.extend "baz"+ {- We get the following type error *before runtime* ! :+ • Unhandled effect 'SA.Extend [Char]'+ Probable fix:+ add an interpretation for 'SA.Extend [Char]'+ • In a stmt of a 'do' block: SA.extend "baz"+ In the third argument of ‘scopedFile’, namely+ ‘do embed . print =<< SA.read SA.ToEnd+ SA.extend "baz"’+ In a stmt of a 'do' block:+ scopedFile+ @ReadAccess+ (Path.Internal.Path "/tmp/polysemy-scoped-fs-test" ::+ Path Abs File)+ do embed . print =<< SA.read SA.ToEnd+ SA.extend "baz"+ -}++-- >>> writeFoobar+-- "foobar"+-- "foobar"+----++== License++This package is mainly licensed under 'AGPL-3.0-or-later'. However,+only the below files partially contain source codes that are licensed+under 'AGPL-3.0-or-later AND BSD-...'. Please see the header comments+in these files for the details. These files also include the copyright+notice, the conditions, and the disclaimer related to the BSD license.++* src/Polysemy/Scoped/Path.hs+* src/Polysemy/Scoped/Path/Internal.hs+* src/Polysemy/FS/Scoped/Internal.hs++=== Submission of Contributions++Unless You explicitly state otherwise, any Contribution intentionally+submitted for inclusion in the Work by You to the Licensor shall be+under the terms and conditions of AGPL-3.0-or-later, without any+additional terms or conditions; where Contribution, Work, You, and+Licensor are as defined in the Apache-2.0 license.
+ README.md view
@@ -0,0 +1,83 @@+# polysemy-scoped-fs++This package provides well-typed (scoped) filesystem operation effects.+This is based on the idea and codes of [Scoped Effect Resources for+Polysemy](https://www.tweag.io/blog/2022-01-05-polysemy-scoped/) by+Torsten Schmits.++## Example++We assume that the language extensions related to polysemy and+polysemy-plugin are enabled. cf.+<https://hackage.haskell.org/package/polysemy-1.7.1.0#readme>++``` haskell+{-# LANGUAGE OverloadedStrings #-}++import qualified Polysemy.SequentialAccess as SA+import Polysemy (runFinal, embedToFinal, embed)+import Polysemy.Resource (resourceToIOFinal)+import Polysemy.Path+import Polysemy.FS.Scoped (scopedFile, AccessMode(RwAccess, ReadAccess))+import Polysemy.FS.Scoped.Text (rwAccessToIO, readAccessToIO)++writeFoobar :: IO ()+writeFoobar =+ runFinal $ embedToFinal $ resourceToIOFinal $ rwAccessToIO $ readAccessToIO $ do+ -- Open the file '/tmp/polysemy-scoped-fs-test' with read & write access mode.+ scopedFile @RwAccess [absfile|/tmp/polysemy-scoped-fs-test|] $ do+ SA.extend "This text will be deleted."+ SA.resize SA.NullSize -- Clear the file.+ SA.extend "foo" -- Append the text to the file.+ SA.extend "bar"+ SA.seek SA.TOF -- Seek to the top of the file.+ embed . print =<< SA.read SA.ToEnd++ -- Open the file with read only access mode.+ scopedFile @ReadAccess [absfile|/tmp/polysemy-scoped-fs-test|] $ do+ embed . print =<< SA.read SA.ToEnd++ -- SA.extend "baz"+ {- We get the following type error *before runtime* ! :+ • Unhandled effect 'SA.Extend [Char]'+ Probable fix:+ add an interpretation for 'SA.Extend [Char]'+ • In a stmt of a 'do' block: SA.extend "baz"+ In the third argument of ‘scopedFile’, namely+ ‘do embed . print =<< SA.read SA.ToEnd+ SA.extend "baz"’+ In a stmt of a 'do' block:+ scopedFile+ @ReadAccess+ (Path.Internal.Path "/tmp/polysemy-scoped-fs-test" ::+ Path Abs File)+ do embed . print =<< SA.read SA.ToEnd+ SA.extend "baz"+ -}++-- >>> writeFoobar+-- "foobar"+-- "foobar"+```++## License++This package is mainly licensed under 'AGPL-3.0-or-later'. However, only+the below files partially contain source codes that are licensed under+'AGPL-3.0-or-later AND BSD-…'. Please see the header comments in these+files for the details. These files also include the copyright notice,+the conditions, and the disclaimer related to the BSD license.++- src/Polysemy/Scoped/Path.hs++- src/Polysemy/Scoped/Path/Internal.hs++- src/Polysemy/FS/Scoped/Internal.hs++### Submission of Contributions++Unless You explicitly state otherwise, any Contribution intentionally+submitted for inclusion in the Work by You to the Licensor shall be+under the terms and conditions of AGPL-3.0-or-later, without any+additional terms or conditions; where Contribution, Work, You, and+Licensor are as defined in the Apache-2.0 license.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ polysemy-scoped-fs.cabal view
@@ -0,0 +1,125 @@+cabal-version: 2.2++-- This file has been generated from package.yaml by hpack version 0.34.4.+--+-- see: https://github.com/sol/hpack++name: polysemy-scoped-fs+version: 0.1.0.0+synopsis: Well-typed filesystem operation effects.+description: Please see the README on GitLab at <https://gitlab.com/hisaket/polysemy-scoped-fs/-/blob/master/README.adoc>+category: Polysemy Filesystem+homepage: https://gitlab.com/hisaket/polysemy-scoped-fs+bug-reports: https://gitlab.com/hisaket/polysemy-scoped-fs/issues+author: Hisaket VioletRed+maintainer: hisaket@outlook.jp+copyright: 2022 Hisaket VioletRed+license: AGPL-3.0-or-later+license-file: LICENSE+build-type: Simple+extra-source-files:+ README.adoc+ ChangeLog.adoc+ README.md+ ChangeLog.md++source-repository head+ type: git+ location: https://gitlab.com/hisaket/polysemy-scoped-fs++library+ exposed-modules:+ Polysemy.Env+ Polysemy.FS.Scoped+ Polysemy.FS.Scoped.ByteString+ Polysemy.FS.Scoped.ByteString.Internal+ Polysemy.FS.Scoped.Internal+ Polysemy.FS.Scoped.Internal.MembersProof+ Polysemy.FS.Scoped.Oneshot+ Polysemy.FS.Scoped.Text+ Polysemy.FS.Scoped.Text.Internal+ Polysemy.Scoped.Path+ Polysemy.Scoped.Path.Internal+ Polysemy.Scoped.Path.Isolation+ Polysemy.ScopedReader+ Polysemy.SequentialAccess+ Polysemy.SequentialAccess.ByteString+ Polysemy.SequentialAccess.Text+ other-modules:+ Paths_polysemy_scoped_fs+ hs-source-dirs:+ src+ default-extensions:+ DataKinds+ FlexibleContexts+ GADTs+ LambdaCase+ PolyKinds+ RankNTypes+ ScopedTypeVariables+ TypeApplications+ TypeOperators+ TypeFamilies+ UnicodeSyntax+ BlockArguments+ TemplateHaskell+ QuasiQuotes+ ghc-options: -flate-specialise -fspecialise-aggressively -fplugin=Polysemy.Plugin -fwarn-incomplete-patterns+ build-depends:+ base >=4.7 && <5+ , bytestring >=0.10.12 && <0.11+ , directory >=1.3.6 && <1.4+ , doctest ==0.17.*+ , extra >=1.7.9 && <1.8+ , path >=0.8.0 && <0.9+ , polysemy >=1.7.1 && <1.8+ , polysemy-fs >=0.1.0 && <0.2+ , polysemy-path >=0.2.0 && <0.3+ , polysemy-plugin >=0.4.3 && <0.5+ , text >=1.2.4 && <1.3+ default-language: Haskell2010+ autogen-modules: Paths_polysemy_scoped_fs++test-suite polysemy-scoped-fs-doctest+ type: exitcode-stdio-1.0+ main-is: test/doctests.hs+ other-modules:+ Paths_polysemy_scoped_fs+ ghc-options: -threaded -rtsopts -with-rtsopts=-N+ build-depends:+ base >=4.7 && <5+ , bytestring >=0.10.12 && <0.11+ , directory >=1.3.6 && <1.4+ , doctest ==0.17.*+ , extra >=1.7.9 && <1.8+ , path >=0.8.0 && <0.9+ , polysemy >=1.7.1 && <1.8+ , polysemy-fs >=0.1.0 && <0.2+ , polysemy-path >=0.2.0 && <0.3+ , polysemy-plugin >=0.4.3 && <0.5+ , polysemy-scoped-fs+ , text >=1.2.4 && <1.3+ default-language: Haskell2010++test-suite polysemy-scoped-fs-test+ type: exitcode-stdio-1.0+ main-is: Spec.hs+ other-modules:+ Paths_polysemy_scoped_fs+ hs-source-dirs:+ test+ ghc-options: -threaded -rtsopts -with-rtsopts=-N+ build-depends:+ base >=4.7 && <5+ , bytestring >=0.10.12 && <0.11+ , directory >=1.3.6 && <1.4+ , doctest ==0.17.*+ , extra >=1.7.9 && <1.8+ , path >=0.8.0 && <0.9+ , polysemy >=1.7.1 && <1.8+ , polysemy-fs >=0.1.0 && <0.2+ , polysemy-path >=0.2.0 && <0.3+ , polysemy-plugin >=0.4.3 && <0.5+ , polysemy-scoped-fs+ , text >=1.2.4 && <1.3+ default-language: Haskell2010
+ src/Polysemy/Env.hs view
@@ -0,0 +1,26 @@+{-|+Copyright : (c) Hisaket VioletRed, 2022+License : AGPL-3.0-or-later+Maintainer : hisaket@outlook.jp+Stability : experimental+-}++module Polysemy.Env where++import Polysemy ( Member, Sem, interpret, makeSem )+import Polysemy.Input ( Input (Input) )++-- | Variant of 'Input' effect that has no side effects.+data Env i m a where+ Env :: Env i m i+makeSem ''Env++{- |Transforms an 'Input' effect into an `Env` effect.+ Note that "askToInput" of inverted version is not provided because an 'Env' effect is specialized version of an 'Input' effect.+-}+inputToEnv :: Member (Env i) r => Sem (Input i ': r) a -> Sem r a+inputToEnv = interpret \Input -> env++-- | Runs an 'Env' effect.+runEnvConst :: i -> Sem (Env i ': r) a -> Sem r a+runEnvConst i = interpret \Env -> pure i
+ src/Polysemy/FS/Scoped.hs view
@@ -0,0 +1,108 @@+{-|+Copyright : (c) Hisaket VioletRed, 2022+License : AGPL-3.0-or-later+Maintainer : hisaket@outlook.jp+Stability : experimental+Portability : POSIX++The behavior about file access mode conforms 'System.IO.IOMode' and 'System.IO.openFile'.+-}++{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE AllowAmbiguousTypes #-}+{-# LANGUAGE UndecidableInstances #-}+{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}+{-# HLINT ignore "Use camelCase" #-}++module Polysemy.FS.Scoped+ ( module Polysemy.FS.Scoped+ , ScopedFile+ , sendBundle_+ , runScopedFile+ )+ where++import Polysemy.Path ( Path, File )+import Polysemy.Bundle ( injBundle, Bundle )+import Polysemy+ ( Member+ , Sem+ , raise2Under+ , raiseUnder+ , subsume+ , InterpretersFor+ , rewrite+ , transform+ )+import Polysemy.Scoped.Path ( ScopedP, scopedP )+import Polysemy.FS.Scoped.Internal+ ( ScopedFile (ScopedFile), sendBundle_, runScopedFile, unScopedFile )+import Polysemy.Input ( Input )+import Polysemy.Internal.Sing ( KnownList )+import Polysemy.Internal.Kind ( Append )+import Control.Category ((>>>))+++scopedFile+ :: ∀accessMode format es b r handle a+ . (Member (ScopedFile (Mode format accessMode) es b handle) r, KnownList es)+ => Path b File -> Sem (Append es (Bundle es ': Input (Path b File) ': r)) a -> Sem r a+scopedFile path = scopedFile_bundle path . sendBundle_++scopedFile_single+ :: ∀accessMode format e es b r handle+ . (Member (ScopedFile (Mode format accessMode) es b handle) r, Member e es)+ => Path b File -> InterpretersFor '[e, Input (Path b File)] r+scopedFile_single path = scopedFile_bundle path . rewrite injBundle++scopedFile_bundle+ :: ∀accessMode format es b r handle+ . Member (ScopedFile (Mode format accessMode) es b handle) r+ => Path b File -> InterpretersFor '[Bundle es, Input (Path b File)] r+scopedFile_bundle path = transform ScopedFile . scopedP path . raise2Under+++{- | A tag type that represents file open mode in POSIX.+-}+data Mode (fmt :: Format) (acc :: AccessMode)++data Format =+ TextFormat+ | BytesFormat++data AccessMode =+ ReadAccess+ -- ^read only access mode ('System.IO.ReadMode')++ | WriteAccess+ -- ^write only access mode ('System.IO.WriteMode')++ | AppendAccess+ -- ^append access mode ('System.IO.AppendMode')++ | RwAccess+ -- ^read write access mode ('System.IO.ReadWriteMode')++-- | A type signature of interpreters for scoped file access.+type Access format accessMode es r b =+ ∀a+ . (∀handle. Sem (ScopedFile (Mode format accessMode) es b handle ': r) a)+ -> Sem r a+++rewriteScopedFile+ :: (Sem (ScopedP (Path b File) handle (Bundle es) ': r) a -> Sem (ScopedP (Path b' File) handle' (Bundle es') ': r) a)+ -> Sem (ScopedFile mode es b handle ': r) a+ -> Sem (ScopedFile mode es' b' handle' ': r) a+rewriteScopedFile f = rewrite unScopedFile >>> f >>> rewrite ScopedFile++transformerToRewriter+ :: (Sem (e0 ': e1 ': r) a -> Sem (e1 ': r) a)+ -> Sem (e0 ': r) a -> Sem (e1 ': r) a+transformerToRewriter f = raiseUnder >>> f++rewriterToTransformer+ :: (∀r. Sem (e0 ': r) a -> Sem (e1 ': r) a)+ -> (∀r. Member e1 r' => Sem (e0 ': r') a -> Sem r' a)+rewriterToTransformer f = f >>> subsume
+ src/Polysemy/FS/Scoped/ByteString.hs view
@@ -0,0 +1,59 @@+{-|+Copyright : (c) Hisaket VioletRed, 2022+License : AGPL-3.0-or-later+Maintainer : hisaket@outlook.jp+Stability : experimental+Portability : POSIX+-}++module Polysemy.FS.Scoped.ByteString where++import Polysemy ( embed, Embed, Members, interpret )+import Polysemy.Resource ( Resource )+import Polysemy.FS.Scoped+ ( Access+ , AccessMode ( ReadAccess, WriteAccess )+ , Format ( BytesFormat )+ )+import Polysemy.SequentialAccess.ByteString as SAB+ ( Cursor, Resize, Append, Overwrite, ReadToEnd, ReadBytes )+import qualified System.IO as IO++import Polysemy.FS.Scoped.ByteString.Internal+import Control.Category hiding ((.))+import qualified Polysemy.SequentialAccess as SA+import qualified Data.ByteString as BS+++-- | An interpreter for read open mode with binary.+readAccessToIO+ :: Members '[Embed IO, Resource] r+ => Access BytesFormat ReadAccess (SAB.ReadBytes ': SAB.ReadToEnd ': SAB.Cursor) r b+readAccessToIO =+ scopedBinaryFileToIO IO.ReadMode+ \h -> readToIO h >>> cursorToIO h++-- | An interpreter for write open mode with binary.+writeAccessToIO+ :: Members '[Embed IO, Resource] r+ => Access BytesFormat WriteAccess (SAB.Overwrite ': SAB.Resize ': SAB.Cursor) r b+writeAccessToIO =+ scopedBinaryFileToIO IO.WriteMode+ \h -> overwriteToIO h >>> resizeToIO h >>> cursorToIO h++-- | An interpreter for read and write open mode with binary.+rwAccessToIO+ :: Members '[Embed IO, Resource] r+ => Access BytesFormat WriteAccess+ (SAB.ReadBytes ': SAB.ReadToEnd ': SAB.Overwrite ': SAB.Resize ': SAB.Cursor) r b+rwAccessToIO =+ scopedBinaryFileToIO IO.ReadWriteMode+ \h -> readToIO h >>> overwriteToIO h >>> resizeToIO h >>> cursorToIO h++-- | An interpreter for append open mode with binary.+appendAccessToIO+ :: Members '[Embed IO, Resource] r+ => Access BytesFormat WriteAccess '[SAB.Append, SAB.Resize] r b+appendAccessToIO =+ scopedBinaryFileToIO IO.AppendMode+ \h -> resizeToIO h . interpret (\(SA.Append s) -> embed $ BS.hPut h s)
+ src/Polysemy/FS/Scoped/ByteString/Internal.hs view
@@ -0,0 +1,51 @@+{-|+Copyright : (c) Hisaket VioletRed, 2022+License : AGPL-3.0-or-later+Maintainer : hisaket@outlook.jp+Stability : experimental+Portability : POSIX+-}++module Polysemy.FS.Scoped.ByteString.Internal where+import Polysemy+ ( Member, Sem, embed, Embed, InterpretersFor, Members, interpret )+import qualified Polysemy.SequentialAccess.ByteString as SAB+import qualified Polysemy.SequentialAccess as SA+import qualified Data.ByteString as BS+import qualified GHC.IO.Handle as IO+import qualified System.IO as IO+import Control.Category ( (>>>) )+import Polysemy.FS.Scoped.Internal ( seekToEnd )+import Polysemy.Internal.Kind ( Append )+import Polysemy.Resource ( Resource )+import Polysemy.Internal.Sing ( KnownList )+import qualified Polysemy.FS.Scoped.Internal as Scoped++readToIO :: Member (Embed IO) r => IO.Handle -> Sem (SAB.ReadBytes ': SAB.ReadToEnd ': r) a -> Sem r a+readToIO h =+ interpret (\(SA.Read n) -> embed $ BS.hGet h $ fromIntegral n)+ >>> interpret+ ( \(SA.Read SA.ToEnd) ->+ embed $ (BS.hGetContents =<< IO.hDuplicate h) <* seekToEnd h+ )++cursorToIO :: Member (Embed IO) r => IO.Handle -> Sem (Append SAB.Cursor r) a -> Sem r a+cursorToIO h =+ interpret (\SA.GetPosition -> embed $ fromIntegral <$> IO.hTell h)+ >>> interpret (\(SA.Seek (SA.Absolute n)) -> embed $ IO.hSeek h IO.AbsoluteSeek $ fromIntegral n)+ >>> interpret (\(SA.Seek (SA.Relative i)) -> embed $ IO.hSeek h IO.RelativeSeek i)+ >>> interpret (\(SA.Seek (SA.FromEnd i)) -> embed $ IO.hSeek h IO.SeekFromEnd i)++overwriteToIO :: Member (Embed IO) r => IO.Handle -> Sem (SAB.Overwrite ': r) a -> Sem r a+overwriteToIO h = interpret \(SA.Overwrite s) -> embed $ BS.hPut h s++resizeToIO :: Member (Embed IO) r => IO.Handle -> Sem (SAB.Resize ': r) a -> Sem r a+resizeToIO h = interpret \(SA.Resize n) -> embed $ IO.hSetFileSize h $ fromIntegral n++scopedBinaryFileToIO+ :: (Members '[Embed IO, Resource] r, KnownList es)+ => IO.IOMode+ -> (IO.Handle -> InterpretersFor es r)+ -> (∀handle'. Sem (Scoped.ScopedFile mode es b handle' ': r) a)+ -> Sem r a+scopedBinaryFileToIO = Scoped.scopedFileToIO IO.openBinaryFile
+ src/Polysemy/FS/Scoped/Internal.hs view
@@ -0,0 +1,152 @@+{-+This module contains the modified source code from polysemy-1.7.1.0 package+under 'BSD-3-Clause'. So that part is only licensed under+'AGPL-3.0-or-later AND BSD-3-Clause', other part is licensed under+'AGPL-3.0-or-later'.+-}++-- -----BEGIN AGPL-3.0-or-later PART-----+-- Copyright (C) 2022 Hisaket VioletRed++{-|+License : See the header comment of the source file of this module.+Maintainer : hisaket@outlook.jp+Stability : experimental+-}++module Polysemy.FS.Scoped.Internal where++import Polysemy+ ( Sem, embed, Embed, InterpretersFor, Members, rewrite )+import Polysemy.Internal.Kind ( Append )+import Polysemy.Bundle ( runBundle, Bundle (Bundle) )+import Polysemy.Internal.Sing+ ( SList (SEnd, SCons), KnownList (singList) )+import Polysemy.Internal.Union+ ( decomp+ , extendMembershipLeft+ , hoist+ , membership+ , ElemOf+ , Union(Union)+ , Weaving(Weaving)+ )+import Polysemy.Internal+ ( Sem, Append, embed, hoistSem, Embed, InterpretersFor, Members )+import Polysemy.Resource ( bracket, Resource )+import qualified System.IO as IO+import Polysemy.Path ( toFilePath, Path, File )+import Polysemy.Scoped.Path ( ScopedP, runScopedP )+import Polysemy.FS.Scoped.Internal.MembersProof+ ( MembersProof (MembersProof), membersProof, membersProofId )++newtype ScopedFile mode es b handle m a =+ ScopedFile { unScopedFile :: ScopedP (Path b File) handle (Bundle es) m a }++scopedFileToIO+ :: (Members '[Embed IO, Resource] r, KnownList es)+ => (FilePath -> IO.IOMode -> IO IO.Handle)+ -> IO.IOMode+ -> (IO.Handle -> InterpretersFor es r)+ -> (∀handle'. Sem (ScopedFile mode es b handle' ': r) a)+ -> Sem r a+scopedFileToIO openFile mode =+ runScopedFile+ (\path -> bracket (embed $ openFile (toFilePath path) mode) (embed . IO.hClose))++runScopedFile+ :: KnownList es+ => (∀x. Path b File -> (handle -> Sem r x) -> Sem r x)+ -> (handle -> InterpretersFor es r)+ -> (∀handle'. Sem (ScopedFile mode es b handle' ': r) a)+ -> Sem r a+runScopedFile acquire interpret m =+ runScopedP acquire (\h -> interpret h . runBundle) $ rewrite unScopedFile m+++seekToBegin :: IO.Handle -> IO ()+seekToBegin h = IO.hSeek h IO.AbsoluteSeek 0++seekToEnd :: IO.Handle -> IO ()+seekToEnd h = IO.hSeek h IO.SeekFromEnd 0++++sendBundle_+ :: ∀es r a+ . KnownList es+ => Sem (Append es (Bundle es ': r)) a+ -> Sem (Bundle es ': r) a+sendBundle_ = sendBundleSListUsingProof es $ membersProofId es+ where es = singList @es++sendBundleSList+ :: Members l es+ => SList l+ -> Sem (Append l (Bundle es ': r)) a+ -> Sem (Bundle es ': r) a+sendBundleSList l = sendBundleSListUsingProof l $ membersProof l++sendBundleSListUsingProof+ :: ∀l es r a+ . SList l+ -> MembersProof l es+ -> Sem (Append l (Bundle es ': r)) a+ -> Sem (Bundle es ': r) a+sendBundleSListUsingProof = \case+ SEnd -> const id+ SCons l ->+ \(MembersProof pr prs) ->+ sendBundleSListUsingProof l prs+ . sendBundleUsing pr+ (extendMembershipLeft @_ @(Bundle es ': r) l membership)++-- -----END AGPL-3.0-or-later PART-----++-- -----BEGIN AGPL-3.0-or-later AND BSD-3-Clause PART-----+{-+Copyright Sandy Maguire (c) 2019+Copyright Hisaket VioletRed (c) 2022++All rights reserved.+-}++-- This function is modified version from 'Polysemy.Bundle.sendBundle' in polysemy-1.7.1.0 package.+sendBundleUsing :: ElemOf e r' -> ElemOf (Bundle r') r -> Sem (e ': r) a -> Sem r a+sendBundleUsing prE prBundle =+ hoistSem $ \u -> case decomp u of+ Right (Weaving e s wv ex ins) ->+ Union prBundle $+ Weaving (Bundle prE e) s (sendBundleUsing prE prBundle . wv) ex ins+ Left g -> hoist (sendBundleUsing prE prBundle) g+{-# INLINE sendBundleUsing #-}++{-+Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Sandy Maguire nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+-}+-- -----END AGPL-3.0-or-later AND BSD-3-Clause PART-----
+ src/Polysemy/FS/Scoped/Internal/MembersProof.hs view
@@ -0,0 +1,34 @@+{-|+Copyright : (c) Hisaket VioletRed, 2022+License : AGPL-3.0-or-later+Maintainer : hisaket@outlook.jp+Stability : experimental+-}++module Polysemy.FS.Scoped.Internal.MembersProof where++import Polysemy ( Members, Effect, EffectRow )+import Polysemy.Internal.Union ( membership, ElemOf (There), )+import Polysemy.Internal.Sing ( SList (SEnd, SCons) )++data MembersProof (es :: EffectRow) (r :: EffectRow) where+ EmptyMembersProof :: MembersProof '[] r+ MembersProof :: ElemOf e r -> MembersProof es r -> MembersProof (e ': es) r++membersProof :: Members es r => SList es -> MembersProof es r+membersProof = \case+ SEnd -> EmptyMembersProof+ SCons xs -> MembersProof membership $ membersProof xs++membersProofId :: SList l -> MembersProof l l+membersProofId = \case+ SEnd -> EmptyMembersProof+ SCons xs -> weakenIdMP $ membersProofId xs++weakenIdMP :: MembersProof l l -> MembersProof (e ': l) (e ': l)+weakenIdMP pr = MembersProof membership $ weakenRightMP pr++weakenRightMP :: MembersProof es r -> MembersProof es (e ': r)+weakenRightMP = \case+ EmptyMembersProof -> EmptyMembersProof+ MembersProof pf pfs -> MembersProof (There pf) $ weakenRightMP pfs
+ src/Polysemy/FS/Scoped/Oneshot.hs view
@@ -0,0 +1,158 @@+{-|+Copyright : (c) Hisaket VioletRed, 2022+License : AGPL-3.0-or-later+Maintainer : hisaket@outlook.jp+Stability : experimental++Unscoped file access and interop with polysemy-fs package.+-}++{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}+{-# HLINT ignore "Use camelCase" #-}+{-# LANGUAGE PartialTypeSignatures #-}++module Polysemy.FS.Scoped.Oneshot where++import Polysemy ( Member, Sem, Members, interpret )+import Polysemy.FS.Scoped+ ( ScopedFile+ , AccessMode (ReadAccess, AppendAccess, WriteAccess)+ , Format (TextFormat, BytesFormat)+ , Mode+ , scopedFile_single+ )+import qualified Polysemy.SequentialAccess.Text as SAT+import qualified Polysemy.SequentialAccess.ByteString as SAB+import qualified Polysemy.SequentialAccess as SA+import Polysemy.Path+ ( toFilePath+ , parseSomeFile+ , Path+ , Abs+ , File+ , PathException+ , Rel+ , SomeBase+ )+import Polysemy.Error ( Error )+import Control.Category ( (>>>) )+import qualified Data.ByteString as BS+import Path ( SomeBase (..) )+import Prelude hiding ( readFile, appendFile )+import qualified Polysemy.FS.Scoped.Text as ST+import qualified Polysemy.FS.Scoped.ByteString as SB+import Polysemy.FS+ ( FSRead (ReadFileBS, ReadFileUtf8)+ , FSWrite (WriteFileBS, WriteFileUtf8)+ )++readFile+ :: (Member (ScopedFile (Mode fmt ReadAccess) es b handle) r, Member (SA.Read SA.ToEnd i) es)+ => Path b File -> Sem r i+readFile path = scopedFile_single path $ SA.read SA.ToEnd++overwriteFile+ :: (Member (ScopedFile (Mode fmt WriteAccess) es b handle) r, Member (SA.Overwrite o) es)+ => Path b File -> o -> Sem r ()+overwriteFile path o = scopedFile_single path $ SA.overwrite o++extendFile+ :: (Member (ScopedFile (Mode fmt WriteAccess) es b handle) r, Member (SA.Extend o) es)+ => Path b File -> o -> Sem r ()+extendFile path o = scopedFile_single path $ SA.extend o++appendFile+ :: (Member (ScopedFile (Mode fmt AppendAccess) es b handle) r, Member (SA.Append o) es)+ => Path b File -> o -> Sem r ()+appendFile path o = scopedFile_single path $ SA.append o++readFile_single+ :: Member (ScopedFile (Mode fmt ReadAccess) '[SA.Read SA.ToEnd i] b handle) r+ => Path b File -> Sem r i+readFile_single = readFile++overwriteFile_single+ :: Member (ScopedFile (Mode fmt WriteAccess) '[SA.Overwrite o] b handle) r+ => Path b File -> o -> Sem r ()+overwriteFile_single = overwriteFile++extendFile_single+ :: Member (ScopedFile (Mode fmt WriteAccess) '[SA.Extend o] b handle) r+ => Path b File -> o -> Sem r ()+extendFile_single = extendFile++appendFile_single+ :: Member (ScopedFile (Mode fmt AppendAccess) '[SA.Append o] b handle) r+ => Path b File -> o -> Sem r ()+appendFile_single = appendFile++++{- | Example:++>>> import Polysemy.Resource ( resourceToIO )+>>> import qualified Polysemy.FS.Scoped.Text as ST+>>> import qualified Polysemy.FS.Scoped.ByteString as SB+>>> import Polysemy.Scoped.Path ( weakenScopedP )+>>> import Polysemy.FS.Scoped ( rewriteScopedFile, transformerToRewriter )+>>> import Polysemy ( runFinal, embedToFinal, subsume_ )+>>> import Polysemy.Error ( errorToIOFinal )+>>> :{+ fsReadToIO :: Sem '[FSRead] a -> IO (Either PathException a)+ fsReadToIO m =+ runFinal $ embedToFinal $ resourceToIO $ errorToIOFinal+ $ ST.readAccessToIO $ rewriteScopedFile (transformerToRewriter $ weakenScopedP @'[SAT.ReadToEnd] @_ @(Path Abs _))+ $ ST.readAccessToIO $ rewriteScopedFile (transformerToRewriter $ weakenScopedP @'[SAT.ReadToEnd] @_ @(Path Rel _))+ $ SB.readAccessToIO $ rewriteScopedFile (transformerToRewriter $ weakenScopedP @'[SAB.ReadToEnd] @_ @(Path Abs _))+ $ SB.readAccessToIO $ rewriteScopedFile (transformerToRewriter $ weakenScopedP @'[SAB.ReadToEnd] @_ @(Path Rel _))+ $ fsReadToScopedRead+ $ subsume_ m+:}++-}++fsReadToScopedRead+ :: ∀handle0 handle1 handle2 handle3 r a+ . Members+ '[ ScopedFile (Mode BytesFormat ReadAccess) '[SAB.ReadToEnd] Abs handle0+ , ScopedFile (Mode BytesFormat ReadAccess) '[SAB.ReadToEnd] Rel handle1+ , ScopedFile (Mode TextFormat ReadAccess) '[SAT.ReadToEnd] Abs handle2+ , ScopedFile (Mode TextFormat ReadAccess) '[SAT.ReadToEnd] Rel handle3+ , Error PathException+ ] r+ => Sem (FSRead ': r) a+ -> Sem r a+fsReadToScopedRead = interpret \case+ ReadFileBS path ->+ toSomeBase path >>= \case+ Abs path -> readFile @BytesFormat path+ Rel path -> readFile @BytesFormat path+ ReadFileUtf8 path ->+ toSomeBase path >>= \case+ Abs path -> readFile @TextFormat path+ Rel path -> readFile @TextFormat path++fsWriteToScopedWrite+ :: ∀handle0 handle1 handle2 handle3 r a+ . Members+ '[ ScopedFile (Mode BytesFormat WriteAccess) '[SAB.Overwrite] Abs handle0+ , ScopedFile (Mode BytesFormat WriteAccess) '[SAB.Overwrite] Rel handle1+ , ScopedFile (Mode TextFormat WriteAccess) '[SAT.Extend] Abs handle2+ , ScopedFile (Mode TextFormat WriteAccess) '[SAT.Extend] Rel handle3+ , Error PathException+ ] r+ => Sem (FSWrite ': r) a+ -> Sem r a+fsWriteToScopedWrite = interpret \case+ WriteFileBS path content ->+ toSomeBase path >>= \case+ Abs path -> overwriteFile @BytesFormat path content+ Rel path -> overwriteFile @BytesFormat path content+ WriteFileUtf8 path content ->+ toSomeBase path >>= \case+ Abs path -> extendFile @TextFormat path content+ Rel path -> extendFile @TextFormat path content++toSomeBase :: Members '[Error PathException] r => Path b File -> Sem r (SomeBase File)+toSomeBase = toFilePath >>> parseSomeFile+-- Perhaps, an error can't occur definitely so the error effect can be removed...
+ src/Polysemy/FS/Scoped/Text.hs view
@@ -0,0 +1,87 @@+{-|+Copyright : (c) Hisaket VioletRed, 2022+License : AGPL-3.0-or-later+Maintainer : hisaket@outlook.jp+Stability : experimental+Portability : POSIX++Example\:++>>> import qualified Polysemy.SequentialAccess as SA+>>> import qualified Polysemy.SequentialAccess.Text as SAT+>>> import Polysemy ( runFinal, embedToFinal, embed )+>>> import Polysemy.Resource ( resourceToIOFinal )+>>> import Polysemy.Path+>>> import Polysemy.FS.Scoped ( scopedFile, AccessMode (RwAccess) )+>>> import Control.Monad.Extra ( whenM )+>>> import System.Directory ( doesFileExist, removeFile )+>>> import Control.Exception ( throwIO )+>>> :{+runFinal $ embedToFinal $ resourceToIOFinal $ rwAccessToIO do + let path = [absfile|/tmp/polysemy-scoped-fs-test|]+ embed $ whenM (doesFileExist $ toFilePath path) $+ throwIO $ userError "Abort to prevent overwriting."+ scopedFile @RwAccess path do+ SA.extend "This text will be deleted."+ SA.resize SA.NullSize+ SA.extend "foo"+ SA.extend "bar"+ SA.seek SA.TOF+ embed . print =<< SA.read SA.ToEnd+ embed $ removeFile $ toFilePath path+:}+"foobar"++-}++module Polysemy.FS.Scoped.Text where++import Polysemy.FS.Scoped.Text.Internal+ ( readToIO, extendToIO, clearToIO, cursorToIO, scopedTextFileToIO )++import Polysemy ( embed, Embed, Members, interpret )+import Polysemy.FS.Scoped+ ( Access+ , AccessMode (ReadAccess, AppendAccess, RwAccess, WriteAccess)+ , Format (TextFormat)+ )+import qualified Polysemy.SequentialAccess.Text as SAT+import qualified System.IO as IO+import qualified Data.Text.IO as TIO+import qualified Polysemy.SequentialAccess as SA+import Control.Category ( (>>>) )+import Polysemy.Resource ( Resource )+++-- | An interpreter for read open mode with text.+readAccessToIO+ :: Members '[Embed IO, Resource] r+ => Access TextFormat ReadAccess (SAT.ReadLine ': SAT.ReadToEnd ': SAT.Cursor) r b+readAccessToIO =+ scopedTextFileToIO IO.ReadMode+ \h -> readToIO h >>> cursorToIO h++-- | An interpreter for write open mode with text.+writeAccessToIO+ :: Members '[Embed IO, Resource] r+ => Access TextFormat WriteAccess (SAT.Extend ': SAT.Clear ': SAT.Cursor) r b+writeAccessToIO =+ scopedTextFileToIO IO.WriteMode+ \h -> extendToIO h >>> clearToIO h >>> cursorToIO h++-- | An interpreter for read and write open mode with text.+rwAccessToIO+ :: Members '[Embed IO, Resource] r+ => Access TextFormat RwAccess+ (SAT.ReadLine ': SAT.ReadToEnd ': SAT.Extend ': SAT.Clear ': SAT.Cursor) r b+rwAccessToIO =+ scopedTextFileToIO IO.ReadWriteMode+ \h -> readToIO h >>> extendToIO h >>> clearToIO h >>> cursorToIO h++-- | An interpreter for append open mode with text.+appendAccessToIO+ :: Members '[Embed IO, Resource] r+ => Access TextFormat AppendAccess '[SAT.Append, SAT.Clear] r b+appendAccessToIO =+ scopedTextFileToIO IO.AppendMode+ \h -> clearToIO h . interpret \(SA.Append t) -> embed $ TIO.hPutStr h t
+ src/Polysemy/FS/Scoped/Text/Internal.hs view
@@ -0,0 +1,70 @@+{-|+Copyright : (c) Hisaket VioletRed, 2022+License : AGPL-3.0-or-later+Maintainer : hisaket@outlook.jp+Stability : experimental+Portability : POSIX+-}++module Polysemy.FS.Scoped.Text.Internal where++import qualified System.IO as IO+import Polysemy+ ( Member, Sem, embed, Embed, InterpretersFor, Members, interpret )+import qualified Polysemy.SequentialAccess.Text as SAT+import qualified Polysemy.SequentialAccess as SA+import Polysemy.Internal.Kind ( Append )+import Polysemy.Resource ( Resource )+import Control.Category ( (>>>) )+import Data.Functor ( (<&>) )+import Polysemy.FS.Scoped.Internal as Scoped+ ( ScopedFile, scopedFileToIO, seekToBegin, seekToEnd )+import qualified Polysemy.FS.Scoped as Scoped+import Polysemy.Internal.Sing ( KnownList )+import qualified Data.Text.IO as TIO+import qualified GHC.IO.Handle as IO+++readToIO :: Member (Embed IO) r => IO.Handle -> Sem (SAT.ReadLine ': SAT.ReadToEnd ': r) a -> Sem r a+readToIO h =+ interpret (\(SA.Read SAT.Line) -> embed $ TIO.hGetLine h)+ >>> interpret+ ( \(SA.Read SA.ToEnd) ->+ embed $ (TIO.hGetContents =<< IO.hDuplicate h) <* seekToEnd h+ )++extendToIO :: Member (Embed IO) r => IO.Handle -> Sem (SAT.Extend ': r) a -> Sem r a+extendToIO h = interpret \(SA.Extend t) -> embed $ restoreCursor h $ seekToEnd h *> TIO.hPutStr h t+++restoreCursor :: IO.Handle -> IO a -> IO a+restoreCursor h m = do+ before <- IO.hTell h+ m <* IO.hSeek h IO.AbsoluteSeek before++clearToIO :: Member (Embed IO) r => IO.Handle -> Sem (SAT.Clear ': r) a -> Sem r a+clearToIO h = interpret \(SA.Resize SA.NullSize) -> embed $ IO.hSetFileSize h 0++cursorToIO :: Member (Embed IO) r => IO.Handle -> Sem (Append SAT.Cursor r) a -> Sem r a+cursorToIO h =+ interpret+ ( \SA.GetPosition -> embed $+ IO.hTell h >>= \case+ 0 -> pure $ SA.End SA.TOF+ _ -> IO.hIsEOF h <&> \case+ False -> SA.Intermediate+ True -> SA.End SA.EOF+ )+ >>> interpret+ (\(SA.Seek end) -> embed $ case end of+ SA.TOF -> seekToBegin h+ SA.EOF -> seekToEnd h+ )++scopedTextFileToIO+ :: (Members '[Embed IO, Resource] r, KnownList es)+ => IO.IOMode+ -> (IO.Handle -> InterpretersFor es r)+ -> (∀handle'. Sem (Scoped.ScopedFile mode es b handle' ': r) a)+ -> Sem r a+scopedTextFileToIO = Scoped.scopedFileToIO IO.openFile
+ src/Polysemy/Scoped/Path.hs view
@@ -0,0 +1,168 @@+{-+This module contains the modified source code from polysemy-conc-0.7.0.0 package+under 'BSD-2-Clause-Patent'. So that part is only licensed under+'AGPL-3.0-or-later AND BSD-2-Clause-Patent', other part is licensed under+'AGPL-3.0-or-later'.+-}++-- -----BEGIN AGPL-3.0-or-later PART-----+-- Copyright (C) 2022 Hisaket VioletRed++{-|+License : See the header comment of the source file of this module.+Maintainer : hisaket@outlook.jp+Stability : experimental+Portability : POSIX+-}++{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}+{-# HLINT ignore "Use camelCase" #-}++module Polysemy.Scoped.Path+ ( module Polysemy.Scoped.Path+ , Polysemy.Scoped.Path.Internal.ScopedP+ )+ where++import Polysemy+ ( Member+ , Sem+ , raise+ , InterpreterFor+ , InterpretersFor+ , Members+ , transform+ )+import Polysemy.Internal ( liftSem, send )+import Polysemy.Internal.Union ( injWeaving, Weaving(Weaving) )+import Control.Category ( (>>>) )+import Polysemy.Input ( Input, runInputConst )+import Polysemy.Bundle ( injBundle, Bundle )+import Polysemy.Scoped.Path.Internal+ ( ScopedP (Run, InScope), bundle, unbundle, weakenBundle, interpretH' )+import Polysemy.Internal.Sing ( KnownList )+++-- | Variant of 'scopedP' in which cannot access to outer scope.+innerScopedP :: Member (ScopedP path resource (Bundle es)) r => path -> Sem es a -> Sem r a+innerScopedP path = scopedP path . bundle++injScopedP+ :: ∀effect es path resource r a+ . (Member (ScopedP path resource (Bundle es)) r, Member effect es)+ => Sem (ScopedP path resource effect ': r) a -> Sem r a+injScopedP = transformScopedP injBundle++unbundleScopedP+ :: Member (ScopedP path resource effect) r+ => Sem (ScopedP path resource (Bundle '[effect]) ': r) a -> Sem r a+unbundleScopedP = transformScopedP unbundle++weakenScopedP+ :: ∀es0 es1 path resource r a+ . (Member (ScopedP path resource (Bundle es1)) r, Members es0 es1, KnownList es0)+ => Sem (ScopedP path resource (Bundle es0) ': r) a -> Sem r a+weakenScopedP = transformScopedP weakenBundle++transformScopedP+ :: (Member (ScopedP path resource e1) r)+ => (∀rInitial x. e0 (Sem rInitial) x -> e1 (Sem rInitial) x)+ -> Sem (ScopedP path resource e0 ': r) a+ -> Sem r a+transformScopedP f = transform \case+ Run res e -> Run res $ f e+ InScope path f -> InScope path f+++type Scoped = ScopedP ()++scoped :: Member (Scoped resource effect) r => InterpreterFor effect r+scoped = scopedP_simple ()+++scopedP+ :: ∀path resource effect r+ . Member (ScopedP path resource effect) r+ => path -> InterpretersFor '[effect, Input path] r+scopedP path =+ scopedP_simple path+ >>> runInputConst path ++-- -----END AGPL-3.0-or-later PART-----+ +-- -----BEGIN AGPL-3.0-or-later AND BSD-2-Clause-Patent PART-----+{-+Copyright (c) 2020 Torsten Schmits+Copyright (c) 2022 Hisaket VioletRed+-}++-- The below functions are modified (or unmodified) version from modules+-- 'Polysemy.Conc.Effect.Scoped' and 'Polysemy.Conc.Interpreter.Scoped' in+-- polysemy-conc-0.7.0.0 package.++scopedP_simple+ :: ∀e path resource effect r a+ . Member (ScopedP path resource effect) r+ => path -> InterpreterFor effect r+scopedP_simple path main =+ send $ InScope path \resource ->+ transform @effect (Run resource) main++scopedP_local+ :: ∀e path resource effect r a+ . Member (ScopedP path resource effect) r+ => (resource -> resource) -> path -> InterpreterFor effect r+scopedP_local f path main =+ send $ InScope path \resource ->+ transform @effect (Run $ f resource) main++runScopedP+ :: ∀path resource effect r+ . (∀x. path -> (resource -> Sem r x) -> Sem r x)+ -> (resource -> InterpreterFor effect r)+ -> InterpreterFor (ScopedP path resource effect) r+runScopedP withResource scopedInterpreter = run+ where+ run :: InterpreterFor (ScopedP path resource effect) r+ run =+ interpretH' \(Weaving effect s wv ex ins) -> case effect of+ Run resource act ->+ scopedInterpreter resource (liftSem $ injWeaving $ Weaving act s (raise . run . wv) ex ins)+ InScope path main ->+ ex <$> withResource path \resource -> run (wv (main resource <$ s))++{-+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the+following conditions are met:++ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following+ disclaimer.+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided with the distribution.++Subject to the terms and conditions of this license, each copyright holder and contributor hereby grants to those+receiving rights under this license a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except+for failure to satisfy the conditions of this license) patent license to make, have made, use, offer to sell, sell,+import, and otherwise transfer this software, where such license applies only to those patent claims, already acquired+or hereafter acquired, licensable by such copyright holder or contributor that are necessarily infringed by:++ (a) their Contribution(s) (the licensed copyrights of copyright holders and non-copyrightable additions of+ contributors, in source or binary form) alone; or+ (b) combination of their Contribution(s) with the work of authorship to which such Contribution(s) was added by such+ copyright holder or contributor, if, at the time the Contribution is added, such addition causes such combination to+ be necessarily infringed. The patent license shall not apply to any other combinations which include the Contribution.++Except as expressly stated above, no rights or licenses from any copyright holder or contributor is granted under this+license, whether expressly, by implication, estoppel or otherwise.++DISCLAIMER++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+-}+-- -----END AGPL-3.0-or-later AND BSD-2-Clause-Patent PART-----
+ src/Polysemy/Scoped/Path/Internal.hs view
@@ -0,0 +1,128 @@+{-+This module contains the modified source code from polysemy-conc-0.7.0.0 package+under 'BSD-2-Clause-Patent'. So that part is only licensed under+'AGPL-3.0-or-later AND BSD-2-Clause-Patent', other part is licensed under+'AGPL-3.0-or-later'.+-}++-- -----BEGIN AGPL-3.0-or-later PART-----+-- Copyright (C) 2022 Hisaket VioletRed++{-|+License : See the header comment of the source file of this module.+Maintainer : hisaket@outlook.jp+Stability : experimental+Portability : POSIX+-}++{-# LANGUAGE EmptyCase #-}++{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}+{-# HLINT ignore "Use camelCase" #-}++module Polysemy.Scoped.Path.Internal where++import Polysemy ( Sem, InterpreterFor, Members )+import Polysemy.Internal.Union+ ( decomp, hoist, membership+ , Union (Union), Weaving (Weaving), ElemOf (Here, There)+ )+import Polysemy.Internal+ ( Sem (Sem, runSem), hoistSem, InterpreterFor, Members )+import Control.Category ((>>>))+import Polysemy.FS.Scoped.Internal.MembersProof ( MembersProof )+import Polysemy.Internal.Sing ( SList (SEnd, SCons), KnownList (singList) )+import Polysemy.Bundle ( Bundle (Bundle) )++-- | Bundle all effects of 'Sem' into a single 'Bundle'.+bundle :: Sem es a -> Sem (Bundle es ': r) a+bundle =+ hoistSem \(Union w (Weaving e s wv ex ins)) ->+ Union Here $ Weaving (Bundle w e) s (bundle . wv) ex ins+++subsumeBundle_id :: Sem (Bundle r ': r) a -> Sem r a+subsumeBundle_id = subsumeBundleUsing id++subsumeBundleUsing :: (∀e. ElemOf e es -> ElemOf e r) -> Sem (Bundle es ': r) a -> Sem r a+subsumeBundleUsing i = hoistSem $ \u -> hoist (subsumeBundleUsing i) $ case decomp u of+ Right (Weaving (Bundle pr e) s wv ex ins) ->+ Union (i pr) (Weaving e s wv ex ins)+ Left g -> g+++unbundle :: Bundle '[e] m a -> e m a+unbundle = \case+ Bundle Here e -> e+ Bundle (There es) e -> case es of++weakenBundle :: (Members es r, KnownList es) => Bundle es m a -> Bundle r m a+weakenBundle (Bundle pr e) = Bundle (weakenMembership pr) e+++weakenMembership :: (Members es r, KnownList es) => ElemOf e es -> ElemOf e r+weakenMembership = weakenMembership' singList++weakenMembership' :: Members es r => SList es -> ElemOf e es -> ElemOf e r+weakenMembership' l pr = case l of+ SEnd -> case pr of+ SCons xs -> case pr of+ Here -> membership+ There pr' -> weakenMembership' xs pr'++-- -----END AGPL-3.0-or-later PART-----+ +-- -----BEGIN AGPL-3.0-or-later AND BSD-2-Clause-Patent PART-----+{-+Copyright (c) 2020 Torsten Schmits+Copyright (c) 2022 Hisaket VioletRed+-}++data ScopedP path resource effect m a where+ Run :: ∀path resource effect m a. resource -> effect m a -> ScopedP path resource effect m a+ InScope :: ∀path resource effect m a. path -> (resource -> m a) -> ScopedP path resource effect m a++interpretH'+ :: (∀x. Weaving e (Sem (e : r)) x -> Sem r x)+ -> InterpreterFor e r+interpretH' h (Sem m) =+ Sem \k -> m $ decomp >>> \case+ Right wav -> runSem (h wav) k+ Left g -> k $ hoist (interpretH' h) g+++{-+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the+following conditions are met:++ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following+ disclaimer.+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided with the distribution.++Subject to the terms and conditions of this license, each copyright holder and contributor hereby grants to those+receiving rights under this license a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except+for failure to satisfy the conditions of this license) patent license to make, have made, use, offer to sell, sell,+import, and otherwise transfer this software, where such license applies only to those patent claims, already acquired+or hereafter acquired, licensable by such copyright holder or contributor that are necessarily infringed by:++ (a) their Contribution(s) (the licensed copyrights of copyright holders and non-copyrightable additions of+ contributors, in source or binary form) alone; or+ (b) combination of their Contribution(s) with the work of authorship to which such Contribution(s) was added by such+ copyright holder or contributor, if, at the time the Contribution is added, such addition causes such combination to+ be necessarily infringed. The patent license shall not apply to any other combinations which include the Contribution.++Except as expressly stated above, no rights or licenses from any copyright holder or contributor is granted under this+license, whether expressly, by implication, estoppel or otherwise.++DISCLAIMER++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+-}+-- -----END AGPL-3.0-or-later AND BSD-2-Clause-Patent PART-----
+ src/Polysemy/Scoped/Path/Isolation.hs view
@@ -0,0 +1,63 @@+{-|+Copyright : (c) Hisaket VioletRed, 2022+License : AGPL-3.0-or-later+Maintainer : hisaket@outlook.jp+Stability : experimental++This module provides methods that allow for isolating effects inside or outside the scope locally.++It will be useful when using the effects for virtualization or containerization such as libvirt or Docker safely.+-}++{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}+{-# HLINT ignore "Use camelCase" #-}++module Polysemy.Scoped.Path.Isolation where+import Polysemy ( Member, Sem, InterpretersFor, Members, rewrite )+import Polysemy.Scoped.Path ( ScopedP, scopedP )+import Polysemy.Input ( Input )+import Polysemy.Bundle ( subsumeBundle, Bundle )+import Control.Category ( (>>>) )+import Polysemy.Scoped.Path.Internal+ ( bundle, subsumeBundleUsing, unbundle )+import Polysemy.Tagged ( tag, untag, Tagged )+import Polysemy.Membership ( ElemOf )++-- | Variant of 'scopedP' that can isolate effects inside or outside the scope locally.+isolatingScopedP+ :: Member (ScopedP path resource effect) r+ => path -> InterpretersFor '[Tagged 'Inner effect, Input path, Tagged 'Outer (Bundle r)] r+isolatingScopedP = isolatingScopedPSubUsing id++-- | Variant of 'scopedP' that can isolate effects inside or outside the scope locally.+-- A version that can isolate only a subset of effects in regards to outside the scope.+isolatingScopedPSub+ :: ∀es path resource effect r+ . (Member (ScopedP path resource effect) r, Members es r)+ => path -> InterpretersFor '[Tagged 'Inner effect, Input path, Tagged 'Outer (Bundle es)] r+isolatingScopedPSub path = untag >>> scopedP path >>> untag >>> subsumeBundle++-- | Variant of 'scopedP' that can isolate effects inside or outside the scope locally.+isolatingScopedPSubUsing+ :: ∀es path resource effect r+ . Member (ScopedP path resource effect) r+ => (∀e. ElemOf e es -> ElemOf e r)+ -> path -> InterpretersFor '[Tagged 'Inner effect, Input path, Tagged 'Outer (Bundle es)] r+isolatingScopedPSubUsing f path = untag >>> scopedP path >>> untag >>> subsumeBundleUsing f++data ScopeSide =+ Inner -- ^ A tag type that represents effects inside the scope.+ | Outer -- ^ A tag type that represents effects outside the scope.++-- | Isolate only effects inside the scope.+inScope :: Member (Tagged Inner (Bundle es)) r => Sem es a -> Sem r a+inScope = bundle >>> tag++-- | Isolate only effects inside the scope.+-- No bundle version.+inScope_single :: Member (Tagged Inner eff) r => Sem '[eff] a -> Sem r a+inScope_single = bundle >>> rewrite unbundle >>> tag++-- | Isolate only effects outside the scope.+outScope :: Member (Tagged Outer (Bundle es)) r => Sem es a -> Sem r a+outScope = bundle >>> tag
+ src/Polysemy/ScopedReader.hs view
@@ -0,0 +1,91 @@+{-|+Copyright : (c) Hisaket VioletRed, 2022+License : AGPL-3.0-or-later+Maintainer : hisaket@outlook.jp+Stability : experimental++This module provides a scoped-reader manner.++In contrast to a normal 'Reader' effect, this manner makes connection of parameter type and effect explicit.++Example\:++>>> import Polysemy ( interpret, runM, embed )+>>> import Polysemy.Output ( Output (Output), output, runOutputSem )++>>> :{+runDebug :: Member (Output String) r => String -> InterpreterFor (ScopedReader String (Output String)) r+runDebug = runScopedReader \i -> interpret \(Output o) -> output $ "[" <> i <> "] " <> o+:}++>>> :{+runM $ runOutputSem (embed . putStrLn) $ runDebug "root" do+ scopedReader $ output "test message 0"+ scopedLocal (<> ".scope-A") do+ scopedReader $ output "test message 1"+ scopedReader $ output "test message 2"+ scopedLocal (<> ".scope-B") do+ scopedReader $ output "test message 3"+:}+[root] test message 0+[root.scope-A] test message 1+[root.scope-A] test message 2+[root.scope-A.scope-B] test message 3++-}++{-# LANGUAGE PartialTypeSignatures #-}+{-# OPTIONS_GHC -Wno-partial-type-signatures #-}++module Polysemy.ScopedReader where++import Polysemy+ ( Member, Sem, raise, raiseUnder, InterpreterFor, transform )+import Polysemy.Scoped.Path ( ScopedP, scopedP_local, runScopedP )+import Polysemy.Scoped.Path.Internal ( interpretH' )+import Control.Category ((>>>))+import Polysemy.Internal ( liftSem )+import Polysemy.Internal.Union+ ( ElemOf (Here), Union (Union), Weaving (Weaving) )+++scopedLocal+ :: ∀i p resource effect r+ . Member (ScopedReader i effect) r+ => (i -> i) -> InterpreterFor (ScopedFix i effect) r+scopedLocal f = scopedFix . scopedP_local f () . raiseUnder++scopedReader :: Member (ScopedReader i effect) r => Sem (effect ': r) a -> Sem r a+scopedReader = scopedEffect++type ScopedReader i effect = ScopedFix i effect++runScopedReader :: (i -> InterpreterFor effect r) -> i -> Sem (ScopedReader i effect ': r) a -> Sem r a+runScopedReader int localEnv = + interpretH' \(Weaving e s wv ex ins) ->+ let send' :: _ -> Sem (_ ': _) _+ send' e' =+ liftSem $ Union Here+ $ Weaving e' s (raise . runScopedReader int localEnv . wv) ex ins+ in case e of+ ScopedEffect e' -> int localEnv $ send' e'+ ScopedFix e' ->+ runScopedP (\() inner -> inner localEnv) (runScopedReader int) $ send' e'+++data ScopedFixP p resource effect m a where+ ScopedEffect :: effect m a -> ScopedFixP p resource effect m a+ ScopedFix+ :: ScopedP p resource (ScopedFixP p resource effect) m a+ -> ScopedFixP p resource effect m a++type ScopedFix = ScopedFixP ()++scopedEffect :: Member (ScopedFixP p resource effect) r => Sem (effect ': r) a -> Sem r a+scopedEffect = transform ScopedEffect++scopedFix+ :: Member (ScopedFixP p resource effect) r+ => Sem (ScopedP p resource (ScopedFixP p resource effect) ': r) a+ -> Sem r a+scopedFix = transform ScopedFix
+ src/Polysemy/SequentialAccess.hs view
@@ -0,0 +1,122 @@+{-|+Copyright : (c) Hisaket VioletRed, 2022+License : AGPL-3.0-or-later+Maintainer : hisaket@outlook.jp+Stability : experimental+Portability : POSIX+-}++module Polysemy.SequentialAccess where++import Polysemy ( Member, Sem, interpret, makeSem )+import Prelude hiding ( Read, read )+import Polysemy.Input ( Input (Input) )+import Polysemy.Output ( Output (Output) )+++data GetPosition pos m a where+ GetPosition :: GetPosition pos m pos+{- ^An effect that gets the current cursor position in the file.+-}+makeSem ''GetPosition++{- |A type that represents both ends or intermediate positions in the file.+-}+data TriPosition = End Ends | Intermediate+ deriving (Eq, Ord, Show)++{- |A type that represents both ends of the file.+-}+data Ends =+ TOF -- ^Top of file+ | EOF -- ^End of file+ deriving (Eq, Ord, Show)+++data Seek pos m a where+ Seek :: pos -> Seek pos m ()+{- ^An effect that moves the cursor.+-}+makeSem ''Seek++{- |A wrapper type that represents an absolute position in the file.+-}+newtype Absolute a = Absolute a deriving (Eq, Ord, Show)++{- |A wrapper type that represents relative position from the current cursor position.+-}+newtype Relative a = Relative a deriving (Eq, Ord, Show)++{- |A wrapper type that represents relative position from the end of the file.+-}+newtype FromEnd a = FromEnd a deriving (Eq, Ord, Show)+++data Read sz i m a where+ Read :: sz -> Read sz i m i+{- ^An effect that gets file contents by the size 'sz' from the current+ position.+-}+makeSem ''Read++{- |An effect that gets file contents from current position to the end of the+ file.+-}+type ReadToEnd = Read ToEnd++{- |A singleton that represents the size from the current position to the end of+ the file.+-}+data ToEnd = ToEnd deriving (Eq, Ord, Show)++-- |A singleton that represents the size 0.+data NullSize = NullSize deriving (Eq, Ord, Show)++{- |Transforms an 'Input' effect into an 'Read' effect with the fixed size.+-}+inputToRead :: Member (Read sz i) r => sz -> Sem (Input i ': r) a -> Sem r a+inputToRead sz = interpret \Input -> read sz+++data Overwrite o m a where+ Overwrite :: o -> Overwrite o m ()+{- ^An effect that overwrites file contents by the data 'o' from current+ position.+-}+makeSem ''Overwrite++{- |Transforms an 'Output' effect into an `Overwrite` effect.+-}+outputToOverwrite :: Member (Overwrite o) r => Sem (Output o ': r) a -> Sem r a+outputToOverwrite = interpret \(Output o) -> overwrite o+++data Extend o m a where+ Extend :: o -> Extend o m ()+-- ^An effect that extends a file by the data 'o' from the end of a file.+-- The cursor is not moved.+makeSem ''Extend++data Append o m a where+ Append :: o -> Append o m ()+-- ^An effect that extends a file by the data 'o' from the end of a file.+-- The cursor is moved to the end of the file after extending.+makeSem ''Append++{- |Transforms an 'Output' effect into an `Extend` effect.+-}+outputToExtend :: Member (Extend o) r => Sem (Output o ': r) a -> Sem r a+outputToExtend = interpret \(Output o) -> extend o++-- |Transforms an 'Output' effect into an `Append` effect.+outputToAppend :: Member (Append o) r => Sem (Output o ': r) a -> Sem r a+outputToAppend = interpret \(Output o) -> append o+++data Resize sz m a where+ Resize :: sz -> Resize sz m ()+{- ^An effect that resizes a file by the size 'sz'.+ + Note: The initial data in space made by a growing is interpreter-dependent.+-}+makeSem ''Resize
+ src/Polysemy/SequentialAccess/ByteString.hs view
@@ -0,0 +1,29 @@+{-|+Description : Sequential access for binary data+Copyright : (c) Hisaket VioletRed, 2022+License : AGPL-3.0-or-later+Maintainer : hisaket@outlook.jp+Stability : experimental+Portability : POSIX++This module is for sequential access to binary data.++In sequential access for binary data, it is allowed to read data by arbitrary+size, and overwrite to, and seek to an arbitrary position.+-}++module Polysemy.SequentialAccess.ByteString where++import qualified Polysemy.SequentialAccess as SA+import Data.ByteString ( ByteString )+import Numeric.Natural ( Natural )++type GetPosition = SA.GetPosition Natural+type ReadBytes = SA.Read Natural ByteString+type ReadToEnd = SA.Read SA.ToEnd ByteString+type Overwrite = SA.Overwrite ByteString+type Append = SA.Append ByteString+type Resize = SA.Resize Natural++type Seek = '[SA.Seek (SA.Absolute Natural), SA.Seek (SA.Relative Integer), SA.Seek (SA.FromEnd Integer)]+type Cursor = GetPosition ': Seek
+ src/Polysemy/SequentialAccess/Text.hs view
@@ -0,0 +1,37 @@+{-|+Description : Sequential access for variable-width encoded text data+Copyright : (c) Hisaket VioletRed, 2022+License : AGPL-3.0-or-later+Maintainer : hisaket@outlook.jp+Stability : experimental+Portability : POSIX++This module is for sequential access to variable-width encoded text data.++In sequential access for variable-width encoded (e.g. UTF-8) text data, It is+allowed to read data per line instead of by arbitrary size.+And, seek operation is only allowed to both ends of a file.++This restriction of safety assumes no writing from others while opening a file.+The behavior is undefined if the assumption is not satisfied. (An encoding corruption occurs typically.)+-}++module Polysemy.SequentialAccess.Text where++import qualified Polysemy.SequentialAccess as SA+import Data.Text ( Text )++type GetPosition = SA.GetPosition SA.TriPosition+type Seek = SA.Seek SA.Ends+type ReadLine = SA.Read Line Text+type ReadToEnd = SA.Read SA.ToEnd Text+type Extend = SA.Extend Text+type Append = SA.Append Text+type Clear = SA.Resize SA.NullSize++{- |A singleton that represents the size from the current position to the next+ line break.+-}+data Line = Line deriving (Eq, Ord, Show)++type Cursor = '[GetPosition, Seek]
+ test/Spec.hs view
@@ -0,0 +1,2 @@+main :: IO ()+main = putStrLn "Test suite not yet implemented"
+ test/doctests.hs view
@@ -0,0 +1,31 @@+module Main where++import Test.DocTest++main :: IO ()+main = doctest $+ map ("-X" <>) exts+ <> ["-fplugin=Polysemy.Plugin"]+ <> ["-isrc", "src/Polysemy/FS/Scoped/Text.hs"]+ <> ["-isrc", "src/Polysemy/ScopedReader.hs"]+ <> ["-isrc", "src/Polysemy/FS/Scoped/Oneshot.hs"]++-- TODO: fetch automatically from package.yaml+exts :: [String]+exts =+ [ "DataKinds"+ , "FlexibleContexts"+ , "GADTs"+ , "LambdaCase"+ , "PolyKinds"+ , "RankNTypes"+ , "ScopedTypeVariables"+ , "TypeApplications"+ , "TypeOperators"+ , "TypeFamilies"+ , "UnicodeSyntax"+ , "BlockArguments"+ , "TemplateHaskell"+ , "QuasiQuotes"+ , "OverloadedStrings"+ ]