{"id":17760577,"url":"https://github.com/fuco1/emacs-cats","last_synced_at":"2025-10-30T23:45:18.469Z","repository":{"id":150147548,"uuid":"617694239","full_name":"Fuco1/emacs-cats","owner":"Fuco1","description":"Functors, Monads, Categories for Emacs","archived":false,"fork":false,"pushed_at":"2023-04-11T13:33:06.000Z","size":94,"stargazers_count":56,"open_issues_count":0,"forks_count":2,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-02-07T07:46:33.203Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Emacs Lisp","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Fuco1.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-22T23:07:16.000Z","updated_at":"2024-12-01T10:53:24.000Z","dependencies_parsed_at":"2024-12-14T06:26:02.979Z","dependency_job_id":"9a3ac3c5-710a-43f6-ad0c-d1e216ddf124","html_url":"https://github.com/Fuco1/emacs-cats","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fuco1%2Femacs-cats","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fuco1%2Femacs-cats/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fuco1%2Femacs-cats/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fuco1%2Femacs-cats/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Fuco1","download_url":"https://codeload.github.com/Fuco1/emacs-cats/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246644097,"owners_count":20810687,"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":[],"created_at":"2024-10-26T19:06:00.950Z","updated_at":"2025-10-30T23:45:18.393Z","avatar_url":"https://github.com/Fuco1.png","language":"Emacs Lisp","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Category theory in Emacs\n\nThis package implements various abstractions from Category Theory\nhighly inspired by Haskell.\n\nThe complete (Haskell) documentation can be found on the\n[hackage](https://hackage.haskell.org/package/base-4.18.0.0).\n\n# Usage\n\nBecause Emacs runtime does not possess any abilities of type\ninference, we must explicitly pass the pure and return constructors to\nsome functions where it is impossible to get from context.  Other than\nthis, the usage and interface is the same as the Haskell libraries.\n\nThe macro `cats-do` can be used to sequence monadic actions in an\nimperative way.  Here is an example of a state monad:\n\n``` emacs-lisp\n(defclass my-state ()\n  ((config-file\n    :initarg :config-file\n    :accessor get-config-file)\n   (working-dir\n    :initarg :working-dir\n    :accessor get-working-dir)))\n\n(defun my-exec-in-wd (cmd)\n  \"Prepare an action running CMD in current state's working directory.\"\n  (cats-do\n   ;; map get-working-dir over the internal state, save the result in\n   ;; variable `wd'\n   (:= wd (cats-fmap #'get-working-dir (cats-state-get)))\n   ;; the first argument to return is only used to determine the\n   ;; \"instance\" of return for state, because Elisp cannot determine\n   ;; this automatically during runtime.\n   (cats-return (cats-data-state)\n     (with-temp-buffer\n       (let ((default-directory wd))\n         (shell-command-to-string cmd))))))\n```\n\nMore comprehensive examples are in the [examples](./examples)\ndirectory.\n\n# Classes and Methods\n\nClasses are implemented by defining one or several `cl-defgeneric`\nmethods which need to be implemented (we call this an *instance*).\nFor example, to make a `list` an instance of class `Functor`, it needs\nto implemment `(cl-defmethod cats-fmap (fn (this list)))` method.\n\nFollowing is a list of classes and corresponding methods.\n\n## Functors\n\nA type `f` is a `Functor` if it provides a function `cats-fmap` which,\ngiven any types `a` and `b` lets you apply any function from `(a -\u003e\nb)` to turn an `f a` into an `f b`, preserving the structure of\n`f`.\n\nExample: a list is a functor with `cats-fmap` equal to `mapcar`.\n\nMinimal implementation of Functor is:\n\n- `cats-fmap`\n\nThe following laws must be satisfied:\n\n``` emacs-lisp\n;; Identity\n  (cats-fmap #'identity a)\n= (identity a)\n\n;; Composition\n  (cats-fmap (lambda (x) (funcall f (funcall g x))) structure)\n= (cats-fmap f (cats-fmap g structure))\n```\n\nInstances for built-in Elisp types:\n\n- `list`\n- `cons`\n- `vector`\n\nInstances for types provided by Cats:\n\n- `cats-data-maybe`\n- `cats-data-ziplist`\n- `cats-data-state`\n\n## Applicative\n\nA functor with application, providing operations to embed pure\nexpressions (`cats-pure`), and sequence computations and combine their\nresults (`cats-apply`).  Unlike Monads, Applicative application can\nnot decide what to do next based on the result of previous action.\n\nEach Applicative must also implement **Functor**.\n\nMinimal implementation of Applicative is:\n\n- `cats-pure`\n- `cats-apply`\n\nAdditional methods:\n\n- `cats-lift-a2`\n\nInstances for built-in Elisp types:\n\n- `list` (non-deterministic)\n- `cons` (zipper)\n- `vector` (non-deterministic)\n\nInstances for types provided by Cats:\n\n- `cats-data-ziplist` is a list wrapper with zipping apply\n- `cats-data-maybe`\n- `cats-data-state`\n\n## Monad\n\nThe Monad class defines the basic operations over a monad, an abstract\ndatatype of actions.  Unlike Applicative, Monad binding can decide\nwhat to do next based on the result of previous action.\n\nEach Monad must also implement **Applicative**.\n\nMinimal implementation of Monad is:\n\n- `cats-return`\n- `cats-bind`\n\nAdditional methods:\n\n- `cats-seq`\n\nThe following laws must be satisfied:\n\n``` emacs-lisp\n;; Left identity\n  (cats-bind (cats-return monad-type a) fn)\n= (funcall fn a)\n\n;; Right identity\n  (cats-bind m (lambda (x) (cats-return monad-type x)))\n= m\n\n;; Associativity\n  (cats-bind m (lambda (x) (cats-bind (funcall k x) h)))\n= (cats-bind (cats-bind m k) h)\n```\n\nInstances for built-in Elisp types:\n\n- `list` (non-deterministic)\n- `vector` (non-deterministic)\n\nInstances for types provided by Cats:\n\n- `cats-data-maybe`\n- `cats-data-state`\n\n## Monoid\n\nThe class of monoids (types with an associative binary operation that\nhas an identity).\n\nMinimal implementation of Monoid is:\n\n- `cats-mempty`\n- `cats-mappend`\n\nAdditional methods:\n\n- `cats-mconcat`\n\nThe following laws must be satisfied:\n\n``` emacs-lisp\n;; Right Identity\n(cats-mappend a (cats-mempty a)) = a\n\n;; Left Identity\n(cats-mappend (cats-mempty a) a) = a\n\n;; Associativity (semigroup)\n  (cats-mappend a (cats-mappend b c))\n= (cats-mappend (cats-mappend a b) c)\n\n;; Concatenation\n  (cats-mconcat list-of-a)\n= (cats-foldr #'cats-mappend (cats-mempty item-of-a) list-of-a)\n```\n\nInstances for built-in Elisp types:\n\n- `list`\n- `vector`\n- `number` (with sum)\n- `string` (with concat)\n\nInstances for types provided by Cats:\n\n- `cats-data-endo` - Monoid of endomorphisms under composition\n\n## Foldable\n\nThe Foldable class represents data structures that can be reduced to a\nsummary value one element at a time.\n\nMinimal implementation of Foldable is:\n\n- `cats-fold-map` or `cats-foldr`\n\nInstances for built-in Elisp types:\n\n- `list`\n- `vector`\n\nInstances for types provided by Cats:\n\n- `cats-data-maybe`\n\n## Traversable\n\nFunctors representing data structures that can be transformed to\nstructures of the same shape by performing an Applicative (or,\ntherefore, Monad) action on each element from left to right.\n\nEach Traversable must also implement **Functor** and **Foldable**.\n\nMinimal implementation of Traversable is:\n\n- `cats-traverse` or `cats-sequence-a`\n\nInstances for built-in Elisp types:\n\n- `list`\n\nInstances for types provided by Cats:\n\n- `cats-data-maybe`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffuco1%2Femacs-cats","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffuco1%2Femacs-cats","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffuco1%2Femacs-cats/lists"}