{"id":18133183,"url":"https://github.com/typedbyte/program","last_synced_at":"2025-04-16T06:17:23.228Z","repository":{"id":56875477,"uuid":"434284958","full_name":"typedbyte/program","owner":"typedbyte","description":"A library for writing programs with environments and managed resources, written in Haskell.","archived":false,"fork":false,"pushed_at":"2021-12-03T13:47:56.000Z","size":7,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-03-14T19:18:25.778Z","etag":null,"topics":["effects","haskell","reader"],"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/typedbyte.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}},"created_at":"2021-12-02T15:57:58.000Z","updated_at":"2023-05-25T17:14:45.000Z","dependencies_parsed_at":"2022-08-20T22:00:40.795Z","dependency_job_id":null,"html_url":"https://github.com/typedbyte/program","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/typedbyte%2Fprogram","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typedbyte%2Fprogram/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typedbyte%2Fprogram/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typedbyte%2Fprogram/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/typedbyte","download_url":"https://codeload.github.com/typedbyte/program/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249207230,"owners_count":21230028,"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":["effects","haskell","reader"],"created_at":"2024-11-01T13:07:07.095Z","updated_at":"2025-04-16T06:17:23.187Z","avatar_url":"https://github.com/typedbyte.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# program\n\n[![Hackage](https://img.shields.io/hackage/v/program.svg?logo=haskell\u0026label=program)](https://hackage.haskell.org/package/program)\n\n[RIO]: https://hackage.haskell.org/package/rio\n[ReaderT]: https://www.fpcomplete.com/blog/2017/06/readert-design-pattern/\n[Handle Pattern]: https://jaspervdj.be/posts/2018-03-08-handle-pattern.html\n[record-of-functions]: https://discourse.haskell.org/t/records-of-functions-and-implicit-parameters/747\n[managed]: https://hackage.haskell.org/package/managed\n[Hackage]: https://hackage.haskell.org/package/program\n\n## Overview\n\n`program` is a library for writing programs with environments and managed resources, written in Haskell. It aims to be simple, has minimal dependencies and combines features of various existing approaches for threading an environment through an application (e.g., [RIO][], [ReaderT][], [Handle Pattern][], [record-of-functions][]) and for managing resources without nested bracket-functions (e.g., [managed][]). The library and its documentation can be found on [Hackage][].\n\n## Example\n\nThe following simple example copies `count` characters from one file to another, where `count` is demanded from the environment `e` by the function `copy` (via `pull`) and supplied by `main`. Note that we do not need to close file handles, because resources are managed automatically.\n\n```haskell\n{-# LANGUAGE FlexibleContexts #-}\n{-# LANGUAGE TypeOperators    #-}\nmodule Example where\n\n-- base\nimport Control.Monad\nimport Control.Monad.IO.Class\nimport System.IO\n\n-- program\nimport Control.Program (Program, Has, manage, pull, runProgram)\n\ncopy :: e `Has` Int =\u003e FilePath -\u003e FilePath -\u003e Program e ()\ncopy from to = do\n  fromHandle \u003c- manage (withFile from ReadMode)\n  toHandle   \u003c- manage (withFile to WriteMode)\n  count      \u003c- pull\n  liftIO . replicateM_ count $\n    hGetChar fromHandle \u003e\u003e= hPutChar toHandle\n\nmain :: IO ()\nmain = do\n  runProgram\n    ( 10 :: Int )\n    ( copy \"/tmp/source\" \"/tmp/target\" )\n```\n\nIn larger applications, the environment would contain many more complex values (all demanded by `Has`) and can also be used to manage mutable state. See the documentation on [Hackage][] for more details.\n\n## Advantages\n\n* Easy to understand (e.g., no unlifting, no type-level wizardry, hardly any language extensions).\n* No need for extra dependencies. All we need is `base`.\n* Mocking is easy by supplying different environments via `runProgram`.\n* No fight with the type inference (i.e., down-to-earth types, hardly any typeclasses).\n* The environment can easily simulate beloved effects like `Reader` and `State`.\n* Easy integration of other effects by putting records-of-functions into the environment.\n* Clear error message because involved types are not overly generic.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypedbyte%2Fprogram","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftypedbyte%2Fprogram","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypedbyte%2Fprogram/lists"}