{"title":"Signature restriction for polymorphic algebraic effects","authors":"TARO SEKIYAMA, TAKESHI TSUKADA, ATSUSHI IGARASHI","doi":"10.1017/s0956796824000054","DOIUrl":"https://doi.org/10.1017/s0956796824000054","url":null,"abstract":"The naive combination of polymorphic effects and polymorphic type assignment has been well known to break type safety. In the literature, there are two kinds of approaches to this problem: one is to restrict how effects are triggered and the other is to restrict how they are implemented. This work explores a new approach to ensuring the safety of the use of polymorphic effects in polymorphic type assignment. A novelty of our work is to restrict <jats:italic>effect interfaces</jats:italic>. To formalize our idea, we employ algebraic effects and handlers, where an effect interface is given by a set of operations coupled with type signatures. We propose <jats:italic>signature restriction</jats:italic>, a new notion to restrict the type signatures of operations and show that signature restriction ensures type safety of a language equipped with polymorphic effects and unrestricted polymorphic type assignment. We also develop a type-and-effect system to enable the use of both of the operations that satisfy and those that do not satisfy the signature restriction in a single program.","PeriodicalId":15874,"journal":{"name":"Journal of Functional Programming","volume":"22 1","pages":""},"PeriodicalIF":1.1,"publicationDate":"2024-05-27","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":null,"resultStr":null,"platform":"Semanticscholar","paperid":"141171807","PeriodicalName":null,"FirstCategoryId":null,"ListUrlMain":null,"RegionNum":3,"RegionCategory":"计算机科学","ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":"","EPubDate":null,"PubModel":null,"JCR":null,"JCRName":null,"Score":null,"Total":0}
{"title":"Asymptotic speedup via effect handlers","authors":"DANIEL HILLERSTRÖM, SAM LINDLEY, JOHN LONGLEY","doi":"10.1017/s0956796824000030","DOIUrl":"https://doi.org/10.1017/s0956796824000030","url":null,"abstract":"We study a fundamental efficiency benefit afforded by delimited control, showing that for certain higher-order functions, a language with advanced control features offers an asymptotic improvement in runtime over a language without them. Specifically, we consider the <jats:italic>generic count</jats:italic> problem in the context of a pure functional base language <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796824000030_inline1.png\" /> <jats:tex-math> ${lambda_{textrm{b}}}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> and an extension <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796824000030_inline2.png\" /> <jats:tex-math> ${lambda_{textrm{h}}}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> with general <jats:italic>effect handlers</jats:italic>. We prove that <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796824000030_inline3.png\" /> <jats:tex-math> ${lambda_{textrm{h}}}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> admits an asymptotically more efficient implementation of generic count than any implementation in <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796824000030_inline4.png\" /> <jats:tex-math> ${lambda_{textrm{b}}}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula>. We also show that this gap remains even when <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796824000030_inline5.png\" /> <jats:tex-math> ${lambda_{textrm{b}}}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> is extended to a language <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796824000030_inline6.png\" /> <jats:tex-math> ${{{{{{lambda_{textrm{a}}}}}}}}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> with <jats:italic>affine effect handlers</jats:italic>, which is strong enough to encode exceptions, local state, coroutines and single-shot continuations. This locates the efficiency difference in the gap between ‘single-shot’ and ‘multi-shot’ versions of delimited control. To our knowledge, these results are the first of their kind for control operators.","PeriodicalId":15874,"journal":{"name":"Journal of Functional Programming","volume":"202 1","pages":""},"PeriodicalIF":1.1,"publicationDate":"2024-04-05","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":null,"resultStr":null,"platform":"Semanticscholar","paperid":"140568980","PeriodicalName":null,"FirstCategoryId":null,"ListUrlMain":null,"RegionNum":3,"RegionCategory":"计算机科学","ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":"","EPubDate":null,"PubModel":null,"JCR":null,"JCRName":null,"Score":null,"Total":0}
{"title":"Static Blame for gradual typing","authors":"CHENGHAO SU, LIN CHEN, LI YANHUI, YUMING ZHOU","doi":"10.1017/s0956796824000029","DOIUrl":"https://doi.org/10.1017/s0956796824000029","url":null,"abstract":"Gradual typing integrates static and dynamic typing by introducing a dynamic type and a consistency relation. A problem of gradual type systems is that dynamic types can easily hide erroneous data flows since consistency relations are not transitive. Therefore, a more rigorous static check is required to reveal these hidden data flows statically. However, in order to preserve the expressiveness of gradually typed languages, static checks for gradually typed languages cannot simply reject programs with potentially erroneous data flows. By contrast, a more reasonable request is to show how these data flows can affect the execution of the program. In this paper, we propose and formalize <jats:italic>Static Blame</jats:italic>, a framework that can reveal hidden data flows for gradually typed programs and establish the correspondence between static-time data flows and runtime behavior. With this correspondence, we build a classification of potential errors detected from hidden data flows and formally characterize the possible impact of potential errors in each category on program execution, without simply rejecting the whole program. We implemented Static Blame on Grift, an academic gradually typed language, and evaluated the effectiveness of Static Blame by mutation analysis to verify our theoretical results. Our findings revealed that Static Blame exhibits a notable level of precision and recall in detecting type-related bugs. Furthermore, we conducted a manual classification to elucidate the reasons behind instances of failure. We also evaluated the performance of Static Blame, showing a quadratic growth in run time as program size increases.","PeriodicalId":15874,"journal":{"name":"Journal of Functional Programming","volume":"252 1","pages":""},"PeriodicalIF":1.1,"publicationDate":"2024-03-25","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":null,"resultStr":null,"platform":"Semanticscholar","paperid":"140302331","PeriodicalName":null,"FirstCategoryId":null,"ListUrlMain":null,"RegionNum":3,"RegionCategory":"计算机科学","ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":"","EPubDate":null,"PubModel":null,"JCR":null,"JCRName":null,"Score":null,"Total":0}
{"title":"Knuth–Morris–Pratt illustrated","authors":"CAMERON MOY","doi":"10.1017/s0956796824000017","DOIUrl":"https://doi.org/10.1017/s0956796824000017","url":null,"abstract":"<p>The Knuth–Morris–Pratt (KMP) algorithm for string search is notoriously difficult to understand. Lost in a sea of index arithmetic, most explanations of KMP obscure its essence. This paper constructs KMP incrementally, using pictures to illustrate each step. The end result is easier to comprehend. Additionally, the derivation uses only elementary functional programming techniques.</p>","PeriodicalId":15874,"journal":{"name":"Journal of Functional Programming","volume":"23 1","pages":""},"PeriodicalIF":1.1,"publicationDate":"2024-01-30","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":null,"resultStr":null,"platform":"Semanticscholar","paperid":"139590358","PeriodicalName":null,"FirstCategoryId":null,"ListUrlMain":null,"RegionNum":3,"RegionCategory":"计算机科学","ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":"","EPubDate":null,"PubModel":null,"JCR":null,"JCRName":null,"Score":null,"Total":0}
{"title":"Sparcl: A language for partially invertible computation","authors":"KAZUTAKA MATSUDA, MENG WANG","doi":"10.1017/s0956796823000126","DOIUrl":"https://doi.org/10.1017/s0956796823000126","url":null,"abstract":"Invertibility is a fundamental concept in computer science, with various manifestations in software development (serializer/deserializer, parser/printer, redo/undo, compressor/decompressor, and so on). Full invertibility necessarily requires bijectivity, but the direct approach of composing bijective functions to develop invertible programs is too restrictive to be useful. In this paper, we take a different approach by focusing on <jats:italic>partially invertible</jats:italic> functions—functions that become invertible if some of their arguments are fixed. The simplest example of such is addition, which becomes invertible when fixing one of the operands. More involved examples include entropy-based compression methods (e.g., Huffman coding), which carry the occurrence frequency of input symbols (in certain formats such as Huffman tree), and fixing this frequency information makes the compression methods invertible. We develop a language <jats:sc>Sparcl</jats:sc> for programming such functions in a natural way, where partial invertibility is the norm and bijectivity is a special case, hence gaining significant expressiveness without compromising correctness. The challenge in designing such a language is to allow ordinary programming (the “partially” part) to interact with the invertible part freely, and yet guarantee invertibility by construction. The language <jats:sc>Sparcl</jats:sc> is linear-typed and has a type constructor to distinguish data that are subject to invertible computation and those that are not. We present the syntax, type system, and semantics of the language and prove that <jats:sc>Sparcl</jats:sc> correctly guarantees invertibility for its programs. We demonstrate the expressiveness of <jats:sc>Sparcl</jats:sc> with examples including tree rebuilding from preorder and inorder traversals, Huffman coding, arithmetic coding, and LZ77 compression.","PeriodicalId":15874,"journal":{"name":"Journal of Functional Programming","volume":"35 1","pages":""},"PeriodicalIF":1.1,"publicationDate":"2024-01-26","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":null,"resultStr":null,"platform":"Semanticscholar","paperid":"139579436","PeriodicalName":null,"FirstCategoryId":null,"ListUrlMain":null,"RegionNum":3,"RegionCategory":"计算机科学","ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":"","EPubDate":null,"PubModel":null,"JCR":null,"JCRName":null,"Score":null,"Total":0}
{"title":"Alice or Bob?: Process polymorphism in choreographies","authors":"EVA GRAVERSEN, ANDREW K. HIRSCH, FABRIZIO MONTESI","doi":"10.1017/s0956796823000114","DOIUrl":"https://doi.org/10.1017/s0956796823000114","url":null,"abstract":"We present PolyChor<jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796823000114_inline1.png\" /> <jats:tex-math> $lambda$ </jats:tex-math> </jats:alternatives> </jats:inline-formula>, a language for higher-order functional <jats:italic>choreographic programming</jats:italic>—an emerging paradigm for concurrent programming. In choreographic programming, programmers write the desired cooperative behaviour of a system of processes and then compile it into an implementation for each process, a translation called <jats:italic>endpoint projection</jats:italic>. Unlike its predecessor, Chor<jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796823000114_inline2.png\" /> <jats:tex-math> $lambda$ </jats:tex-math> </jats:alternatives> </jats:inline-formula>, PolyChor<jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796823000114_inline3.png\" /> <jats:tex-math> $lambda$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> has both type and <jats:italic>process</jats:italic> polymorphism inspired by System F<jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796823000114_inline4.png\" /> <jats:tex-math> $_omega$ </jats:tex-math> </jats:alternatives> </jats:inline-formula>. That is, PolyChor<jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796823000114_inline5.png\" /> <jats:tex-math> $lambda$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> is the first (higher-order) functional choreographic language which gives programmers the ability to write generic choreographies and determine the participants at runtime. This novel combination of features also allows PolyChor<jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796823000114_inline6.png\" /> <jats:tex-math> $lambda$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> processes to communicate <jats:italic>distributed values</jats:italic>, leading to a new and intuitive way to write delegation. While some of the functional features of PolyChor<jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796823000114_inline7.png\" /> <jats:tex-math> $lambda$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> give it a weaker correspondence between the semantics of choreographies and their endpoint-projected concurrent systems than some other choreographic languages, we still get the hallmark end result of choreographic programming: projected programmes are dead","PeriodicalId":15874,"journal":{"name":"Journal of Functional Programming","volume":"9 1","pages":""},"PeriodicalIF":1.1,"publicationDate":"2024-01-23","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":null,"resultStr":null,"platform":"Semanticscholar","paperid":"139561776","PeriodicalName":null,"FirstCategoryId":null,"ListUrlMain":null,"RegionNum":3,"RegionCategory":"计算机科学","ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":"","EPubDate":null,"PubModel":null,"JCR":null,"JCRName":null,"Score":null,"Total":0}
{"title":"PhD Abstracts","authors":"Graham Hutton","doi":"10.1017/S0956796823000138","DOIUrl":"https://doi.org/10.1017/S0956796823000138","url":null,"abstract":"Developing reliable software for the Internet of Things (IoT) is difficult because IoT systems are dynamic, interactive, distributed, collaborative, multi-tiered","PeriodicalId":15874,"journal":{"name":"Journal of Functional Programming","volume":"48 3","pages":""},"PeriodicalIF":1.1,"publicationDate":"2024-01-05","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":null,"resultStr":null,"platform":"Semanticscholar","paperid":"139381691","PeriodicalName":null,"FirstCategoryId":null,"ListUrlMain":null,"RegionNum":3,"RegionCategory":"计算机科学","ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":"","EPubDate":null,"PubModel":null,"JCR":null,"JCRName":null,"Score":null,"Total":0}
{"title":"Trace contracts","authors":"CAMERON MOY, MATTHIAS FELLEISEN","doi":"10.1017/s0956796823000096","DOIUrl":"https://doi.org/10.1017/s0956796823000096","url":null,"abstract":"<p>Behavioral software contracts allow programmers to strengthen the obligations and promises that they express with conventional types. They lack expressive power, though, when it comes to invariants that hold across several function calls. Trace contracts narrow this expressiveness gap. A trace contract is a predicate over the sequence of values that flow through function calls and returns. This paper presents a principled design, an implementation, and an evaluation of trace contracts.</p>","PeriodicalId":15874,"journal":{"name":"Journal of Functional Programming","volume":"283 2 1","pages":""},"PeriodicalIF":1.1,"publicationDate":"2023-12-13","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":null,"resultStr":null,"platform":"Semanticscholar","paperid":"138580519","PeriodicalName":null,"FirstCategoryId":null,"ListUrlMain":null,"RegionNum":3,"RegionCategory":"计算机科学","ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":"","EPubDate":null,"PubModel":null,"JCR":null,"JCRName":null,"Score":null,"Total":0}
{"title":"Certified, total serialisers with an application to Huffman encoding","authors":"RALF HINZE","doi":"10.1017/s095679682200017x","DOIUrl":"https://doi.org/10.1017/s095679682200017x","url":null,"abstract":"<p>The other day, I was assembling lecture material for a course on Agda. Pursuing an application-driven approach, I was looking for correctness proofs of popular algorithms. One of my all-time favourites is Huffman data compression (Huffman, 1952). Even though it is probably safe to assume that you are familiar with this algorithmic gem, a brief reminder of the essential idea may not be amiss.</p>","PeriodicalId":15874,"journal":{"name":"Journal of Functional Programming","volume":"140 1","pages":""},"PeriodicalIF":1.1,"publicationDate":"2023-12-12","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":null,"resultStr":null,"platform":"Semanticscholar","paperid":"138573957","PeriodicalName":null,"FirstCategoryId":null,"ListUrlMain":null,"RegionNum":3,"RegionCategory":"计算机科学","ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":"","EPubDate":null,"PubModel":null,"JCR":null,"JCRName":null,"Score":null,"Total":0}
{"title":"Level-p-complexity of Boolean functions using thinning, memoization, and polynomials","authors":"JULIA JANSSON, PATRIK JANSSON","doi":"10.1017/s0956796823000102","DOIUrl":"https://doi.org/10.1017/s0956796823000102","url":null,"abstract":"<p>This paper describes a purely functional library for computing level-<span>p</span>-complexity of Boolean functions and applies it to two-level iterated majority. Boolean functions are simply functions from <span>n</span> bits to one bit, and they can describe digital circuits, voting systems, etc. An example of a Boolean function is majority, which returns the value that has majority among the <span>n</span> input bits for odd <span>n</span>. The complexity of a Boolean function <span>f</span> measures the <span>cost</span> of evaluating it: how many bits of the input are needed to be certain about the result of <span>f</span>. There are many competing complexity measures, but we focus on level-<span>p</span>-complexity — a function of the probability <span>p</span> that a bit is 1. The level-<span>p</span>-complexity <span><span><img data-mimesubtype=\"png\" data-type=\"\" src=\"https://static.cambridge.org/binary/version/id/urn:cambridge.org:id:binary:20231209151452171-0101:S0956796823000102:S0956796823000102_inline1.png\"><span data-mathjax-type=\"texmath\"><span>$D_p(f)$</span></span></img></span></span> is the minimum expected cost when the input bits are independent and identically distributed with Bernoulli(<span>p</span>) distribution. We specify the problem as choosing the minimum expected cost of all possible decision trees — which directly translates to a clearly correct, but very inefficient implementation. The library uses thinning and memoization for efficiency and type classes for separation of concerns. The complexity is represented using (sets of) polynomials, and the order relation used for thinning is implemented using polynomial factorization and root counting. Finally, we compute the complexity for two-level iterated majority and improve on an earlier result by J. Jansson.</p>","PeriodicalId":15874,"journal":{"name":"Journal of Functional Programming","volume":"10 1","pages":""},"PeriodicalIF":1.1,"publicationDate":"2023-12-12","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":null,"resultStr":null,"platform":"Semanticscholar","paperid":"138573960","PeriodicalName":null,"FirstCategoryId":null,"ListUrlMain":null,"RegionNum":3,"RegionCategory":"计算机科学","ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":"","EPubDate":null,"PubModel":null,"JCR":null,"JCRName":null,"Score":null,"Total":0}