{"id":16661396,"url":"https://github.com/bodigrim/logict","last_synced_at":"2025-05-16T13:03:04.622Z","repository":{"id":47573607,"uuid":"184319726","full_name":"Bodigrim/logict","owner":"Bodigrim","description":"A continuation-based backtracking logic programming monad","archived":false,"fork":false,"pushed_at":"2024-11-13T23:10:15.000Z","size":175,"stargazers_count":89,"open_issues_count":3,"forks_count":13,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-14T06:14:10.224Z","etag":null,"topics":["backtracking","logic-programming","logict","monad-transformers"],"latest_commit_sha":null,"homepage":"https://hackage.haskell.org/package/logict","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Bodigrim.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-30T19:28:20.000Z","updated_at":"2025-05-01T23:06:46.000Z","dependencies_parsed_at":"2024-09-10T01:33:33.692Z","dependency_job_id":"11b16000-56d1-4e79-8300-3ded54cee8f5","html_url":"https://github.com/Bodigrim/logict","commit_stats":{"total_commits":175,"total_committers":13,"mean_commits":"13.461538461538462","dds":0.5085714285714286,"last_synced_commit":"22227efc382a852d1bcedfc86c46412b640a6b84"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bodigrim%2Flogict","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bodigrim%2Flogict/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bodigrim%2Flogict/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bodigrim%2Flogict/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Bodigrim","download_url":"https://codeload.github.com/Bodigrim/logict/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254535826,"owners_count":22087398,"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","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":["backtracking","logic-programming","logict","monad-transformers"],"created_at":"2024-10-12T10:34:49.913Z","updated_at":"2025-05-16T13:03:04.604Z","avatar_url":"https://github.com/Bodigrim.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# logict [![Build Status](https://github.com/Bodigrim/logict/workflows/Haskell-CI/badge.svg)](https://github.com/Bodigrim/logict/actions?query=workflow%3AHaskell-CI) [![Hackage](http://img.shields.io/hackage/v/logict.svg)](https://hackage.haskell.org/package/logict) [![Stackage LTS](http://stackage.org/package/logict/badge/lts)](http://stackage.org/lts/package/logict) [![Stackage Nightly](http://stackage.org/package/logict/badge/nightly)](http://stackage.org/nightly/package/logict)\n\nProvides support for logic-based evaluation.  Logic-based programming\nuses a technique known as backtracking to consider alternative values\nas solutions to logic statements, and is exemplified by languages\nsuch as [Prolog](https://wikipedia.org/wiki/Prolog) and\n[Datalog](https://wikipedia.org/wiki/Datalog).\n\nLogic-based programming replaces explicit iteration and sequencing\ncode with implicit functionality that internally \"iterates\" (via\nbacktracking) over a set of possible values that satisfy explicitly\nprovided conditions.\n\nThis package adds support for logic-based programming in Haskell using\nthe continuation-based techniques adapted from the paper\n[Backtracking, Interleaving, and Terminating Monad Transformers](http://okmij.org/ftp/papers/LogicT.pdf)\nby Oleg Kiselyov, Chung-chieh Shan, Daniel P. Friedman, Amr Sabry.\nThis paper extends previous research into using `MonadPlus`\nfunctionality—where `mplus` is used to specify value alternatives\nfor consideration and `mzero` use used to specify the lack of any\nacceptable values—to add support for fairness and pruning using a\nset of operations defined by a new `MonadLogic` class.\n\n# Background\n\nIn a typical example for Prolog logic programming, there are a set of\nfacts (expressed as unconditional statements):\n\n```prolog\nparent(sarah, john).\nparent(arnold, john).\nparent(john, anne).\n```\n\nand a set of rules that apply if their conditions (body clause) are satisfied:\n\n```prolog\ngrandparent(Person, Grandchild) :- parent(Person, X), parent(X, Grandchild).\n```\n\nExecution of a query for this rule `grandparent(G, anne)` would result in the following \"values\":\n\n```prolog\ngrandparent(sarah, anne).\ngrandparent(arnold, anne).\n```\n\nFor this query execution, `Person` and `X` are \"free\" variables where\n`Grandchild` has been fixed to `anne`. The Prolog engine internally\n\"backtracks\" to the `parent(Person, X)` statement to try different\nknown values for each variable, executing forward to see if the values\nsatisfy all the results and produce a resulting value.\n\n# Haskell logict Package\n\nThe Haskell equivalent for the example above, using the `logict` package\nmight look something like the following:\n\n```haskell\nimport Control.Applicative\nimport Control.Monad.Logic\n\nparents :: [ (String, String) ]\nparents = [ (\"Sarah\",  \"John\")\n          , (\"Arnold\", \"John\")\n          , (\"John\",   \"Anne\")\n          ]\n\ngrandparent :: String -\u003e Logic String\ngrandparent grandchild = do (p, c) \u003c- choose parents\n                            (c', g) \u003c- choose parents\n                            guard (c == c')\n                            guard (g == grandchild)\n                            pure p\n\nchoose = foldr ((\u003c|\u003e) . pure) empty\n\nmain = do let grandparents = observeAll (grandparent \"Anne\")\n          putStrLn $ \"Anne's grandparents are: \" \u003c\u003e show grandparents\n```\n\nIn this simple example, each of the `choose` calls acts as a\nbacktracking choice point where different entries of the `parents`\narray will be generated.  This backtracking is handled automatically\nby the `MonadLogic` instance for `Logic` and does not need to be\nexplicitly written into the code.  The `observeAll` function collects\nall the values \"produced\" by `Logic`, allowing this program to\ndisplay:\n\n```\nAnne's grandparents are: [\"Sarah\",\"Arnold\"]\n```\n\nThis example is provided as the `grandparents` executable built by the\n`logict` package so you can run it yourself and try various\nexperimental modifications.\n\nThe example above is very simplistic and is just a brief introduction\ninto the capabilities of logic programming and the `logict` package.\nThe `logict` package provides additional functionality such as:\n\n * Fair conjunction and disjunction, which can help with potentially\n   infinite sets of inputs.\n\n * A `LogicT` monad stack that lets logic operations be performed\n   along with other monadic actions (e.g. if the parents sample was\n   streamed from an input file using the `IO` monad).\n\n * A `MonadLogic` class which allows other monads to be defined which\n   provide logic programming capabilities.\n\n## Additional Notes\n\nThe implementation in this `logict` package provides the backtracking\nfunctionality at a lower level than that defined in the associated\npaper.  The backtracking is defined within the `Alternative` class as\n`\u003c|\u003e` and `empty`, whereas the paper uses the `MonadPlus` class and\nthe `mplus` and `mzero` functions; since `Alternative` is a\nrequirement (constraint) for `MonadPlus`, this allows both\nnomenclatures to be supported and used as appropriate to the client\ncode.\n\nMore details on using this package as well as other functions\n(including fair conjunction and disjunction) are provided in the\n[Haddock documentation](https://hackage.haskell.org/package/logict).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbodigrim%2Flogict","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbodigrim%2Flogict","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbodigrim%2Flogict/lists"}