{"id":16313954,"url":"https://github.com/lysxia/coq-simple-io","last_synced_at":"2025-07-27T08:43:28.372Z","repository":{"id":36311136,"uuid":"132653878","full_name":"Lysxia/coq-simple-io","owner":"Lysxia","description":"IO for Gallina","archived":false,"fork":false,"pushed_at":"2025-02-27T23:41:49.000Z","size":331,"stargazers_count":32,"open_issues_count":3,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-16T02:53:29.060Z","etag":null,"topics":["coq","extraction","ocaml"],"latest_commit_sha":null,"homepage":"https://lysxia.github.io/coq-simple-io/","language":"Coq","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Lysxia.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":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-05-08T19:13:54.000Z","updated_at":"2025-02-27T23:41:13.000Z","dependencies_parsed_at":"2024-04-08T08:48:48.113Z","dependency_job_id":"829358aa-c92e-40de-b2d5-1ca9a4e8820e","html_url":"https://github.com/Lysxia/coq-simple-io","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lysxia%2Fcoq-simple-io","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lysxia%2Fcoq-simple-io/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lysxia%2Fcoq-simple-io/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lysxia%2Fcoq-simple-io/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Lysxia","download_url":"https://codeload.github.com/Lysxia/coq-simple-io/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243882226,"owners_count":20363107,"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":["coq","extraction","ocaml"],"created_at":"2024-10-10T21:52:46.769Z","updated_at":"2025-03-16T14:30:48.220Z","avatar_url":"https://github.com/Lysxia.png","language":"Coq","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Purely functional IO for Coq\n\n[![CircleCI](https://dl.circleci.com/status-badge/img/gh/Lysxia/coq-simple-io/tree/master.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/Lysxia/coq-simple-io/tree/master)\n\n## Hello World in Coq\n\n```coq\nFrom SimpleIO Require Import SimpleIO.\nFrom Coq Require Import String.\n#[local] Open Scope string_scope.\n\nDefinition main : IO unit :=\n  print_endline \"Hello, world!\".\n\nRunIO main.\n```\n\nThe `coq-simple-io` library provides tools to implement IO programs directly in Coq, in a\nsimilar style to Haskell.\n\n- IO monad\n- Bindings to OCaml standard library\n- `RunIO` command for running programs\n\nFacilities for formal verification are not included.\nThere is no canonical way to describe the effects of the arbitrary foreign\nconstructs that this library allows, so this library commits to none.\n\nA possible workflow is to generalize your program to any monad with a\ncertain interface, specialize it to a mathematical monad (*e.g.*, state, or free monad)\nfor formal verification, and to IO for execution.\n[coqffi](https://github.com/coq-community/coqffi) provides a toolchain for\ngenerating such interfaces from OCaml interfaces.\n\n## Installation\n\n### From OPAM\n\n```\nopam install coq-simple-io\n```\n\n### From this repository as a local package\n\n```\n# Clone this repository\ngit clone https://github.com/Lysxia/coq-simple-io\n\n# Register it with opam (the last argument is the path to the repo)\nopam pin add coq-simple-io ./coq-simple-io\n```\n\n## Documentation\n\nThe documentation of the latest released version is available on website at\nhttps://lysxia.github.io/coq-simple-io/toc.html\n\nConsult the [OCaml user manual](https://caml.inria.fr/pub/docs/manual-ocaml/)\nfor detailed description of extracted code.\n\n## Interface\n\nTo use this library:\n\n```coq\nRequire Import SimpleIO.SimpleIO.\n\n(* And to use the monadic notations: *)\nImport IO.Notations.\nLocal Open Scope io_scope.\n\n(* Equivalent notations can be found ext-lib, using its [Monad] type class. *)\n```\n\nCombinators for IO actions.\n\n```coq\nParameter IO : Type -\u003e Type.\n\nModule IO.\n\nParameter ret : forall {a}, a -\u003e IO a.\nParameter bind : forall {a b}, IO a -\u003e (a -\u003e IO b) -\u003e IO b.\nParameter fix_io : forall {a b}, ((a -\u003e IO b) -\u003e (a -\u003e IO b)) -\u003e a -\u003e IO b.\n(* etc. *)\n\nModule Notations.\nNotation \"c \u003e\u003e= f\" := (bind c f)\nNotation \"f =\u003c\u003c c\" := (bind c f)\nNotation \"x \u003c- c1 ;; c2\" := (bind c1 (fun x =\u003e c2))\nNotation \"e1 ;; e2\" := (_ \u003c- e1%io ;; e2%io)%io\nNotation delay io := (delay_io (fun _ =\u003e io)).\nEnd Notations.\n\nEnd IO.\n```\n\n## Define IO actions\n\nThe `IO` type extracts to the following definition in OCaml:\n\n```ocaml\n(* Implicitly [forall r, (a -\u003e r) -\u003e r]. *)\ntype 'a coq_IO = ('a -\u003e Obj.t) -\u003e Obj.t\n```\n\nSo an effectful function `f : t -\u003e u -\u003e v` in OCaml can be wrapped\nas a Coq function `f : t -\u003e u -\u003e IO v` in the following way:\n\n```coq\nParameter f : t -\u003e u -\u003e IO v.\nExtract Constant f =\u003e \"fun a b k -\u003e k (f a b)\".\n```\n\nBasically, add an extra parameter `k` and apply it to the OCaml function call.\n\nThis boilerplate can also be generated from OCaml interfaces using\n[coqffi](https://github.com/coq-community/coqffi).\n\n## Run\n\nThe `RunIO` command extracts and runs an action of type `IO unit`.\n\n```coq\nDefinition main : IO unit :=\n  print_endline \"Hello, world!\".\n\nRunIO main.\n```\n\n### Run as a command-line script\n\nYou can run a `.v` file from the command line with `coqc`.\nTo forward stdin and stdout to your `RunIO` scripts,\nset the option `RunIO IOMode Forward`.\n\n```coq\nFrom SimpleIO Require Import SimpleIO.\nImport IO.Notations.\n\nRunIO IOMode Forward.\n\nDefinition cat : IO unit :=\n  _ \u003c- catch_eof\n    (IO.fix_io (fun f _ =\u003e\n      input \u003c- read_line ;;\n      print_endline input ;;\n      f tt :\u003e IO unit) tt) ;;\n  IO.ret tt.\n\nRunIO cat.\n```\n\n### Configuration\n\n```coq\n(* Open MyModule at the top of the extracted code *)\nRunIO Open \"MyModule\".\n\n(* Build with ocamlfind (default) *)\nRunIO Builder Ocamlfind.\n\n(* Build with dune, specifying a dune file. *)\nRunIO Builder Dune \"dune\".\n\n(* Build with ocamlbuild. It must be installed separately.\n\n     opam install ocamlbuild\n *)\nRunIO Builder Ocamlbuild.\n\n(* `RunIO Builder` can also take extra arguments for the build command in a string. *)\nRunIO Builder Ocamlfind \"-rectypes\".\n\n(* Include my-package when compiling (only for builders Ocamlfind and Ocamlbuild;\n   Dune is configured via the dune file). *)\nRunIO Package \"my-package\".\n\n(* Copy my-directory to the build location so it will be visible to ocamlbuild or dune. *)\nRunIO Include \"my-directory\".\n\n(* Enable or disable automatic detection of common dependencies (on by default):\n   - zarith for bigint representation of integers\n   - coq-core.kernel for Uint63 *)\nRunIO Smart On.\nRunIO Smart Off.\n```\n\nNew `RunIO` options may be added in the future.\nTo avoid risks of future collisions with the main `RunIO` command,\nuse names with a lower case initial (like `RunIO main`),\nor put the action name in parentheses (like `RunIO (Builder)` to run the `IO` action `Builder`).\n\n## Library organization\n\nThe source code can be found under `src/`.\n\n- `SimpleIO.SimpleIO`: Reexports default modules.\n\n### Default modules\n\nThe following modules are imported with `SimpleIO.SimpleIO`.\n\n- `SimpleIO.IO_Monad`: Definition of `IO` and basic combinators.\n- `SimpleIO.IO_Stdlib`: Wrappers around `Stdlib` from OCaml's standard library.\n- `SimpleIO.IO_StdlibAxioms`: Basic theory for pure `Stdlib` functions.\n- `SimpleIO.IO_Exceptions`: Catch common exceptions.\n- `SimpleIO.IO_RawChar`: Utilities that rely on `ExtrOcamlString`.\n- `SimpleIO.IO_String`: Operations on OCaml strings.\n\n### Auxiliary modules\n\nThe following module can be imported separately.\nThey correspond to modules from the OCaml standard library.\n\n- `SimpleIO.IO_Bytes`: Mutable byte sequences.\n- `SimpleIO.IO_Random`: Pseudo-random number generators (PRNG).\n- `SimpleIO.IO_Float`: Floating-point arithmetic.\n- `SimpleIO.IO_Unix`: Interface to the Unix system.\n- `SimpleIO.IO_Sys`: System interface.\n\n### Unsafe modules\n\n- `SimpleIO.IO_Unsafe`: Unsafe operations.\n- `SimpleIO.IO_UnsafeNat`: `Pervasives` functions adapted to `nat`\n  (unsafety because of overflow and underflow).\n\n## Related\n\n- [coqffi](https://github.com/coq-community/coqffi)\n- [Ynot](https://github.com/ynot-harvard/ynot)\n- [Coq.io](http://coq.io)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flysxia%2Fcoq-simple-io","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flysxia%2Fcoq-simple-io","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flysxia%2Fcoq-simple-io/lists"}