{"id":13800638,"url":"https://github.com/purescript-contrib/purescript-quickcheck-laws","last_synced_at":"2026-03-07T16:31:26.930Z","repository":{"id":29816702,"uuid":"33361167","full_name":"purescript-contrib/purescript-quickcheck-laws","owner":"purescript-contrib","description":"QuickCheck powered law tests for PureScript's core typeclasses.","archived":false,"fork":false,"pushed_at":"2022-10-17T15:34:55.000Z","size":173,"stargazers_count":25,"open_issues_count":9,"forks_count":18,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-06-23T04:55:36.301Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PureScript","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/purescript-contrib.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-03T11:54:06.000Z","updated_at":"2024-05-31T14:04:24.000Z","dependencies_parsed_at":"2022-08-28T12:50:38.024Z","dependency_job_id":null,"html_url":"https://github.com/purescript-contrib/purescript-quickcheck-laws","commit_stats":null,"previous_names":["purescript/purescript-quickcheck-laws","garyb/purescript-quickcheck-laws"],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purescript-contrib%2Fpurescript-quickcheck-laws","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purescript-contrib%2Fpurescript-quickcheck-laws/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purescript-contrib%2Fpurescript-quickcheck-laws/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purescript-contrib%2Fpurescript-quickcheck-laws/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/purescript-contrib","download_url":"https://codeload.github.com/purescript-contrib/purescript-quickcheck-laws/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242635336,"owners_count":20161437,"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-08-04T00:01:14.593Z","updated_at":"2026-01-11T13:28:59.954Z","avatar_url":"https://github.com/purescript-contrib.png","language":"PureScript","readme":"# QuickCheck Laws\n\n[![CI](https://github.com/purescript-contrib/purescript-quickcheck-laws/workflows/CI/badge.svg?branch=main)](https://github.com/purescript-contrib/purescript-quickcheck-laws/actions?query=workflow%3ACI+branch%3Amain)\n[![Release](https://img.shields.io/github/release/purescript-contrib/purescript-quickcheck-laws.svg)](https://github.com/purescript-contrib/purescript-quickcheck-laws/releases)\n[![Pursuit](https://pursuit.purescript.org/packages/purescript-quickcheck-laws/badge)](https://pursuit.purescript.org/packages/purescript-quickcheck-laws)\n[![Maintainer: garyb](https://img.shields.io/badge/maintainer-garyb-teal.svg)](https://github.com/garyb)\n\nQuickCheck-powered law tests for PureScript's core typeclasses.\n\n## Installation\n\nInstall `quickcheck-laws` with [Spago](https://github.com/purescript/spago):\n\n```sh\nspago install quickcheck-laws\n```\n\n## Quick start\n\nBelow is an example of how to test the laws of the `Functor` typeclass for a new\ntype `Pair` that we create. On running this code, 1000 tests of the two\n`Functor` laws (identity and composition) will be sucessfully run.\n\n```purs\nmodule Main (main) where\n\n-- The relevent imports\nimport Prelude\nimport Effect (Effect)\nimport Test.QuickCheck.Arbitrary (class Arbitrary, arbitrary)\nimport Test.QuickCheck.Laws.Data.Functor (checkFunctor)\nimport Type.Proxy (Proxy(Proxy))\n\n-- A type to test the `Functor` instance of\ndata Pair a = Pair a a\n\n-- We need an `Eq` instance to check whether two different calls to `map` result\n-- in the same value\nderive instance Eq a =\u003e Eq (Pair a)\n\n-- We need to be able to generate values of type `Pair a`, assuming that we can\n-- generate values of type `a`\ninstance Arbitrary a =\u003e Arbitrary (Pair a) where\n  arbitrary = Pair \u003c$\u003e arbitrary \u003c*\u003e arbitrary\n\n-- The `Functor` that we want to test. There are multiple ways of defining a\n-- functor over `Pair` but here we pick a simple and obvious one\ninstance Functor Pair where\n  map f (Pair x y) = Pair (f x) (f y)\n\n-- We are going to need to \"pass `Pair` into the function `checkFunctor`\". Since\n-- we can't pass types (or type constructors) into functions directly, we create\n-- a proxy that we can pass in\nproxy :: Proxy Pair\nproxy = Proxy\n\n-- Finally, we can run the test by passing the proxy into `checkFunctor`\nmain :: Effect Unit\nmain = do\n  checkFunctor proxy\n```\n\nThe above code implements a law-abiding instance of `Functor` and therefore the\ntests all pass with a message:\n\n```text\nChecking 'Identity' law for Functor\n1000/1000 test(s) passed.\nChecking 'Composition' law for Functor\n1000/1000 test(s) passed.\n```\n\nIf we change the implementation of map to, say,\n\n```purs\n  map _ (Pair x y) = Pair y x\n```\n\nwe get an instance of `Functor` that isn't at all law-abiding. It ignores the\nfirst argument and swaps the elements of the `Pair`. Sure enough, if we run the\ntests on this version we get an error message informing us that one of the tests\nhas failed.\n\nAdditional examples of successful tests can be found in\n[the test suite](./test).\n\n## Documentation\n\n`quickcheck-laws` documentation is stored in a few places:\n\n1. Module documentation is [published on Pursuit](https://pursuit.purescript.org/packages/purescript-quickcheck-laws).\n2. Usage examples can be found in [the test suite](./test).\n\nIf you get stuck, there are several ways to get help:\n\n- [Open an issue](https://github.com/purescript-contrib/purescript-quickcheck-laws/issues) if you have encountered a bug or problem.\n- [Search or start a thread on the PureScript Discourse](https://discourse.purescript.org) if you have general questions. You can also ask questions in the `#purescript` and `#purescript-beginners` channels on the [Functional Programming Slack](https://functionalprogramming.slack.com) ([invite link](https://fpchat-invite.herokuapp.com/)).\n\n## Contributing\n\nYou can contribute to `quickcheck-laws` in several ways:\n\n1. If you encounter a problem or have a question, please [open an issue](https://github.com/purescript-contrib/purescript-quickcheck-laws/issues). We'll do our best to work with you to resolve or answer it.\n\n2. If you would like to contribute code, tests, or documentation, please [read the contributor guide](./CONTRIBUTING.md). It's a short, helpful introduction to contributing to this library, including development instructions.\n\n3. If you have written a library, tutorial, guide, or other resource based on this package, please share it on the [PureScript Discourse](https://discourse.purescript.org)! Writing libraries and learning resources are a great way to help this library succeed.\n","funding_links":[],"categories":["Testing"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpurescript-contrib%2Fpurescript-quickcheck-laws","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpurescript-contrib%2Fpurescript-quickcheck-laws","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpurescript-contrib%2Fpurescript-quickcheck-laws/lists"}