{"id":33054812,"url":"https://github.com/kztk-m/sparcl","last_synced_at":"2025-12-03T10:01:00.752Z","repository":{"id":40277637,"uuid":"274913558","full_name":"kztk-m/sparcl","owner":"kztk-m","description":"Copied from https://bitbucket.org/kztk/partially-reversible-lang-impl/","archived":false,"fork":false,"pushed_at":"2022-12-16T09:36:36.000Z","size":365,"stargazers_count":9,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-28T00:34:38.465Z","etag":null,"topics":["domain-specific-language","functional-programming","haskell","linear-types","reversible-computation","reversible-programming-language"],"latest_commit_sha":null,"homepage":"","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kztk-m.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-06-25T12:43:13.000Z","updated_at":"2023-09-22T04:10:40.000Z","dependencies_parsed_at":"2022-08-09T15:59:13.115Z","dependency_job_id":null,"html_url":"https://github.com/kztk-m/sparcl","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kztk-m/sparcl","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kztk-m%2Fsparcl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kztk-m%2Fsparcl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kztk-m%2Fsparcl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kztk-m%2Fsparcl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kztk-m","download_url":"https://codeload.github.com/kztk-m/sparcl/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kztk-m%2Fsparcl/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27473698,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-03T02:00:06.367Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["domain-specific-language","functional-programming","haskell","linear-types","reversible-computation","reversible-programming-language"],"created_at":"2025-11-14T04:00:21.846Z","updated_at":"2025-12-03T10:01:00.746Z","avatar_url":"https://github.com/kztk-m.png","language":"Haskell","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"readme":"Sparcl: A Language for Partially-Invertible Computation\n=======================================================\n\nThis is an implementation of a system presented in the following paper.\n\n    Kazutaka Matsuda and Meng Wang: Sparcl: A Language for Partially-Invertible Computation, ICFP 2020. \n    \n\nHow to Use\n----------\n\nFirst, install [`ghcup`](https://www.haskell.org/ghcup/) following the instruction found in the link. Then, install `ghc` and `cabal` via `ghcup` by:\n\n    ghcup install cabal \n    ghcup install ghc 9.6.7\n\nOnce this has been done, then type as below to build the system.\n\n    cabal build\n    \nThe command may take some time as it builds all required packages.\n\nThen, we can start the read-eval-print loop by:\n\n    cabal run\n    \nAfter invoking the executable, one will see that the system shows the following prompt.\n\n    Sparcl\u003e \n\nOne thing users can do is to input an expression to examine its evaluation results.\n\n    Sparcl\u003e 1 + 2 \n    3 \n\nAlso, users can ask the inferred type of an expression.\n\n    Sparcl\u003e :type \\x -\u003e x \n    ...\n    forall a b. b # a -\u003e b \n\nWe have some examples under `./Examples` in this distribution. Seeing `./Examples/T1.sparcl` would be useful for knowing the syntax of Sparcl. The loading can be done by the command `:load`.\n\n    Sparcl\u003e :load Examples/T1.sparcl \n    ...\n    \nThen, you can use types and functions defined in the file.\n\n    Sparcl\u003e fwd (add (S Z)) (S (S Z))\n    ...\n    S (S (S Z))\n    Sparcl\u003e bwd (add (S Z)) (S (S (S Z)))\n    ...\n    S (S Z)\n    \n\nTyping `:help` and then enter will show the help as below.\n\n    Sparcl\u003e :help\n    :quit\n        Quit REPL.\n    :load FILEPATH\n        Load a program.\n    :reload\n        Reload the last program.\n    :help\n        Show this help.\n    :type EXP\n        Print the expression's type.\n\nCurrently, there is no batch execution mode. Invoking the executable with a file name is equivalent to invoking it without a file name and executing command `:load`.\n\nSynopses of `Examples`\n----------------------\n\nThere are roughly two sorts of examples, focusing on linear typing and partial invertibility respectively.\n\n### Examples concerning Linear Typing\n\n* `App.sparcl`, `App0.sparcl`, `App1.sparcl`, `App10.sparcl`:\nNested applications of the function application function.\n* `F.sparcl`:\nSome higher-order functions extracted from Haskell's `Prelude`.\n* `GV_func.sparcl`:\nAn example taken from the papers J. Garret Morris: The Best of Both Worlds Linear Functional Programming without Compromise, ICFP 2016, and Sam Lindley: Embedding Session Types in Haskell, Haskell 2016.\n* `T2.sparcl`, `T3.sparcl`, `T4.sparcl`, `T5.sparcl`:\nMiscellaneous examples, mainly used for debugging purpose.\n\n`App*.sparcl`, `F.sparcl` and `GV_func.sparcl` are used in the experiments in Kazutaka Matsuda: \"Modular Inference of Linear Types for Multiplicity-Annotated Arrows\". ESOP 2020.\n\n### Examples concerning Partially Invertible Computation\n\nIn the following, section numbers refer to those in the paper.\n\n* `Fib.sparcl`: An invertible function that computes a consecutive fibonacci numbers from an index.\n* `S2l.sparcl`: An invertible function that computes differences of two consecutive elements in a list (Sections 1 and 2)\n* `Pi.sparcl`: An invertible function that computes pre- and in-order traversals (Section 4.1)\n* `Huff.sparcl`: An invertible version of Huffman coding (Section 4.2)\n* `Loop.sparcl`: An implementation of the trace operator (mentioned in Section 3.6.4).\n* `ArithmeticCoding.sparcl`: An invertible implementation of arithmetic coding.\n* `Reverse.sparcl`: Invertible definitions of the list reversal function.\n* `T1.sparcl`: Miscellaneous examples (including `add` and `mul` discussed in Section 2).\n* `IllTyped1.sparcl`: A non-example that should be rejected by Sparcl's type checker.\n\nNotable Differences from the Paper (ICFP 2020)\n---------------------------------------------\n\n* The concrete syntax is different (in particular, this implementation\n  uses a non-indentation-sensitive syntax, and the keyword `rev` is used instead of non-ascii bullets to mark invertible types)\n* The interpreter uses value environments (as usual) instead of substitutions. HOAS-like representations are adopted for values; particularly, function values are represented by `Value -\u003e Eval Value` where `Eval` is a monad used for the (unidirectional) evaluation. This applies also to residuals, which are represented by pairs of functions implementing the forward and backward evaluations.\n* The forward evaluation ignores linearity.\n* The `Eval` monad mentioned above is used for providing fresh names of invertible variables, which essentially implements alpha renaming mentioned in Fig. 3.\n\nRough Explanation of Syntax\n--------------------------\n\nHere, we briefly explain the syntax of Sparcl. This explanation is not a complete documentation, but only to help understand the examples.\n\nA program consists of type or function definitions. A type declaration can be datatype declarations, or type synonym declarations.\n\n    data T a1 ... an = C Ty1 ... Tym | ... | C' Ty1' ... Tyk\n    type T a1 ... an = T Ty1 ... Tym\n    \nTheir syntax is a similar to Haskell's one.\nUnlike Haskell, there is no partial applications of types and each type variable must range over types or multiplicities.\nCurrently, the system does not have kind-checking.\nSo, it may accept some ill-formed type declarations.\n\nWe also allow GADTs, but use a different syntax from Haskell's. See, `GV_func.sparcl` for an example.\n\nTypes in Sparcl include following ones.\n\n* primitive types (such as `Int`, `Char` and `Bool`)\n* type constructor applications (such as `List Int`)\n* multiplicity-annotated function types (such as `Int # Omega -\u003e Bool`)\n* tuple types (such as `(Int, Bool)`)\n* polymorphic types (with constraints) (such as `forall a p. a # p -\u003e a` and `forall a b p q r. p \u003c= q =\u003e (a # p -\u003e b) # r -\u003e a # q -\u003e b`)\n* invertible types (such as `rev Int` and `rev (List Int)`)\n\nSparcl's type system is rank 1 and polymorphic types can appear in limited positions,\nnamely outermost positions of signature declarations (i.e., `Ty` of `sig f : Ty` below).\n\nA function definition has the form of:\n\n    sig f : Ty \n    def f p1 ... pn = e1 with e1' \n        | ...\n        | q1 ... qn = ek with e2' \n        \nHere, the `with` part is required only if patterns of a branch contain an invertible patterns `rev p`. Branches with invertible patterns will be converted to invertible `case`s internally, while there is no such special `case` expression in the surface language.\nThe `sig` declaration is optional.\n\nOther than invertible patterns `rev p`, patterns can also be:\n\n* variable patterns (such as `x`)\n* constructor patterns (such as `Cons a x` and `Nil`)\n* tuple patterns (such as `(x,y)` and `()`)\n\nInvertible patterns cannot be nested. Value patterns and guards are not supported yet.\n\nExpressions are rather standard except invertible constructors `rev C`. We can use:\n\n* variable expressions\n* constructor expressions (such as `Cons`)\n* tuple expressions (such as `(1, 2)`)\n* applications (such as `f 1`)\n* case expressions (such as `case x of | Nil -\u003e True | Cons _ _ -\u003e False end`)\n* non-recursive let-expression (such as `let rev (x, y) \u003c- e1 in e2`)\n\nNotice that `case` expressions require closing delimiters.\n\nLocal definitions are supported via `let ... in e` and `where ... end`.  The former is an expression while the latter can only appear after a branch (such as `def f x = y where def y = 1 end` and `case 1 of x -\u003e y where def y = 1 end end`).\n\nPublications\n------------\n\n* Kazutaka Matsuda and Meng Wang: \"Sparcl: A Language for Partially-Invertible Computation\". J. Funct. Program. 34: e4 (2024)\n* Kazutaka Matsuda and Meng Wang: \"Sparcl: A Language for Partially-Invertible Computation\". ICFP 2020: 118:1-118:31\n* Kazutaka Matsuda: \"Modular Inference of Linear Types for Multiplicity-Annotated Arrows\". ESOP 2020: 456-483\n\nKnown Issues\n------------\n\n* The importing feature is not thoroughly tested yet.\n* We are experimenting code generation for integration to other systems such as Haskell/GHC. This functionality is partially implemented and the system places such generated Haskell files under the directory `.sparcl`.\n* The primitive operations now have linear function types (such as `(+) : Int -o Int -o Int`), but they may have unrestricted function types (such as `(+) : Int -\u003e Int -\u003e Int`).\n* Pretty-printing for tuple values is suboptimal.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkztk-m%2Fsparcl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkztk-m%2Fsparcl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkztk-m%2Fsparcl/lists"}