{"id":13681778,"url":"https://github.com/fakedata-haskell/fakedata","last_synced_at":"2025-12-11T23:28:42.674Z","repository":{"id":39967484,"uuid":"166589344","full_name":"fakedata-haskell/fakedata","owner":"fakedata-haskell","description":"Haskell Library for producing quality fake data","archived":false,"fork":false,"pushed_at":"2024-10-20T06:00:40.000Z","size":1123,"stargazers_count":149,"open_issues_count":7,"forks_count":21,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-28T17:11:23.345Z","etag":null,"topics":["fake","fake-data","haskell","random"],"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/fakedata-haskell.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-01-19T20:18:31.000Z","updated_at":"2025-02-25T18:57:25.000Z","dependencies_parsed_at":"2024-08-02T13:21:18.237Z","dependency_job_id":"fc18e901-b7e9-491a-acc6-65c7185587ae","html_url":"https://github.com/fakedata-haskell/fakedata","commit_stats":{"total_commits":606,"total_committers":9,"mean_commits":67.33333333333333,"dds":0.04950495049504955,"last_synced_commit":"450bcfd795c34e424051cd472fcf63251693d27a"},"previous_names":["psibi/fakedata"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fakedata-haskell%2Ffakedata","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fakedata-haskell%2Ffakedata/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fakedata-haskell%2Ffakedata/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fakedata-haskell%2Ffakedata/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fakedata-haskell","download_url":"https://codeload.github.com/fakedata-haskell/fakedata/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247226215,"owners_count":20904465,"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":["fake","fake-data","haskell","random"],"created_at":"2024-08-02T13:01:35.691Z","updated_at":"2025-12-11T23:28:37.642Z","avatar_url":"https://github.com/fakedata-haskell.png","language":"Haskell","funding_links":[],"categories":["Haskell"],"sub_categories":[],"readme":"![fakedata](https://user-images.githubusercontent.com/737477/53658993-54575200-3c80-11e9-9125-fbcf9e54660f.png)\n[![Hackage](https://img.shields.io/hackage/v/fakedata.svg)](https://hackage.haskell.org/package/fakedata)\n[![Stackage\nNightly](http://stackage.org/package/fakedata/badge/nightly)](http://stackage.org/nightly/package/fakedata)\n[![Stackage\nLTS](http://stackage.org/package/fakedata/badge/lts)](http://stackage.org/lts/package/fakedata)\n![Build Status](https://github.com/psibi/fakedata/workflows/Tests/badge.svg?branch=master)\n\n\u003c!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-refresh-toc --\u003e\n**Table of Contents**\n\n- [fakedata](#fakedata)\n- [Tutorial](#tutorial)\n  - [Generating address](#generating-address)\n  - [Generating name](#generating-name)\n  - [Generate quotes from the movie Back to the Future](#generate-quotes-from-the-movie-back-to-the-future)\n  - [Combining Fake datas](#combining-fake-datas)\n- [Deterministic vs Non Deterministic values](#deterministic-vs-non-deterministic-values)\n- [Combinators](#combinators)\n  - [listOf](#listof)\n  - [oneOf](#oneof)\n  - [suchThat](#suchthat)\n- [Using the `FakeT` transformer](#using-the-faket-transformer)\n- [Comparision with other libraries](#comparision-with-other-libraries)\n- [Acknowledgments](#acknowledgments)\n\n\u003c!-- markdown-toc end --\u003e\n\n\n# fakedata\n\nThis library is a port of Ruby's [faker](https://github.com/stympy/faker). It's a library for\nproducing fake data such as names, addressess and phone numbers. Note\nthat it directly uses the source data from that library, so the\nquality of fake data is quite high!\n\nThis package comes in handy when you have to generate large amount of\nreal like data for various purposes. I have personally used it for\nwebsites where it needs some realistic data in the initial stage,\nloading database with real like values etc. There are companies which\nhave used this [for sophisphicated testing purpose](https://www.reddit.com/r/haskell/comments/o5n71e/fakedata10_haskell_library_for_producing_quality/h2qxw8a?utm_source=share\u0026utm_medium=web2x\u0026context=3).\n\nAdditionly, there are two other packages for creating generators which\nis useful for property testing:\n\n* [fakedata-quickcheck](https://github.com/fakedata-haskell/fakedata-quickcheck)\n* [hedgehog-fakedata](https://github.com/parsonsmatt/hedgehog-fakedata)\n\n# Tutorial\n\n## Generating address\n\n``` haskell\n~/g/fakedata (master) $ stack ghci\nλ\u003e import Faker\nλ\u003e import Faker.Address\nλ\u003e address \u003c- generate fullAddress\nλ\u003e address\n\"Apt. 298 340 Ike Mission, Goldnertown, FL 19488-9259\"\n```\n\n## Generating name\n\n``` haskell\nλ\u003e fullName \u003c- generate name\nλ\u003e fullName\n\"Sherryl Steuber\"\n```\n\n## Generate quotes from the movie Back to the Future\n\n``` haskell\nλ\u003e import Faker.Movie.BackToTheFuture\nλ\u003e import Faker.Combinators\nλ\u003e qs \u003c- generateNonDeterministic $ listOf 5 quotes\nλ\u003e qs\n[ \"Yes. Yes. I'm George. George McFly. I'm your density. I mean, your destiny.\"\n, \"Hello? Hello? Anybody home? Huh? Think, McFly. Think! I gotta have time to get them retyped. Do you realize what would happen if I hand in my reports in your handwriting? I'll get fired. You wouldn't want that to happen, would ya? Would ya?\"\n, \"Lorraine. My density has brought me to you.\"\n, \"See you in about 30 years.\"\n, \"You really think I ought to swear?\"\n]\n```\n\n## Combining Fake datas\n\n``` haskell\n{-#LANGUAGE RecordWildCards#-}\n\nimport Faker\nimport Faker.Name\nimport Faker.Address\nimport Data.Text\n\ndata Person = Person {\n    personName :: Text,\n    personAddress :: Text\n} deriving (Show, Eq)\n\nfakePerson :: Fake Person\nfakePerson = do\n    personName \u003c- name\n    personAddress \u003c- fullAddress\n    pure $ Person{..}\n\nmain :: IO ()\nmain = do\n    person \u003c- generate fakePerson\n    print person\n```\n\nAnd on executing them:\n\n``` haskell\n$ stack name.hs\nPerson\n  { personName = \"Sherryl Steuber\"\n  , personAddress = \"Apt. 298 340 Ike Mission, Goldnertown, FL 19488-9259\"\n  }\n```\n\nYou would have noticed in the above output that the name and address are\nthe same as generated before in the GHCi REPL. That's because, by\ndefault all the generated data are deterministic. If you want a\ndifferent set of output each time, you would have to modify the random\ngenerator output:\n\n``` haskell\nmain :: IO ()\nmain = do\n    gen \u003c- newStdGen\n    let settings = setRandomGen gen defaultFakerSettings\n    person \u003c- generateWithSettings settings fakePerson\n    print person\n```\n\nAnd on executing the program, you will get a different output:\n\n``` haskell\nPerson\n  { personName = \"Ned Effertz Sr.\"\n  , personAddress = \"Suite 158 1580 Schulist Mall, Schulistburgh, NY 15804-3392\"\n  }\n```\n\nThe above program can be even minimized like this:\n\n``` haskell\nmain :: IO ()\nmain = do\n    let settings = setNonDeterministic defaultFakerSettings\n    person \u003c- generateWithSettings settings fakePerson\n    print person\n```\n\nOr even better:\n\n``` haskell\nmain :: IO ()\nmain = do\n    person \u003c- generateNonDeterministic fakePerson\n    print person\n```\n\n# Deterministic vs Non Deterministic values\n\nWe have various function for generating fake values:\n\n- generate\n- generateNonDeterministic\n- generateNonDeterministicWithFixedSeed\n\nBy default, `generate` produces deterministic values. It's performance\nis better than the others and for cases where we are going to generate\na single fake value using record type, it's a good default to\nhave. Example:\n\n``` haskell\n{-#LANGUAGE RecordWildCards#-}\n\nimport Faker\nimport Faker.Name\nimport Faker.Address\nimport Data.Text\n\ndata Person = Person {\n    personName :: Text,\n    personAddress :: Text\n} deriving (Show, Eq)\n\nfakePerson :: Fake Person\nfakePerson = do\n    personName \u003c- name\n    personAddress \u003c- fullAddress\n    pure $ Person{..}\n\nmain :: IO ()\nmain = do\n    person \u003c- generate fakePerson\n    print person\n```\n\nAnd executing it, you will get:\n\n``` haskell\nPerson\n  { personName = \"Sherryl Steuber\"\n  , personAddress = \"Apt. 298 340 Ike Mission, Goldnertown, FL 19488-9259\"\n  }\n```\n\nWhile, it's a good default we would need non deterministic output for\ncertain cases:\n\n``` haskell\n\u003e generate $ listOf 5 $ fromRange (1,100)\n[39,39,39,39,39]\n\u003e generate $ listOf 5 $ fromRange (1,100)\n[39,39,39,39,39]\n\u003e generateNonDeterministic $ listOf 5 $ fromRange (1,100)\n[94,18,17,48,17]\n\u003e generateNonDeterministic $ listOf 5 $ fromRange (1,100)\n[15,2,47,85,94]\n```\n\nNot how `generateNonDeterministic` is generating different values each\ntime. If you instead want to have a fixed seed, you should use\n`generateNonDeterministicWithFixedSeed` instead:\n\n``` haskell\n\u003e generateNonDeterministicWithFixedSeed $ listOf 5 $ fromRange (1,100)\n[98,87,77,33,98]\n\u003e generateNonDeterministicWithFixedSeed $ listOf 5 $ fromRange (1,100)\n[98,87,77,33,98]\n```\n\n# Combinators\n\n## listOf\n\n``` haskell\nλ\u003e import Faker.Address\nλ\u003e item \u003c- generateNonDeterministic $ listOf 5 country\nλ\u003e item\n[\"Ecuador\",\"French Guiana\",\"Faroe Islands\",\"Canada\",\"Armenia\"]\n```\n\n## oneOf\n\n``` haskell\nλ\u003e item \u003c- generate $ oneof [country, fullAddress]\nλ\u003e item\n\"Suite 599 599 Brakus Flat, South Mason, MT 59962-6876\"\n```\n\n## suchThat\n\n``` haskell\nλ\u003e import qualified Faker.Address as AD\nλ\u003e item :: Text \u003c- generate $ suchThat AD.country (\\x -\u003e (T.length x \u003e 5))\nλ\u003e item\n\"Ecuador\"\nλ\u003e item :: Text \u003c- generate $ suchThat AD.country (\\x -\u003e (T.length x \u003e 8))\nλ\u003e item\n\"French Guiana\"\n```\n\nFor seeing the full list of combinators, see the module documentation of\n`Faker.Combinators`.\n\n\n# Using the `FakeT` transformer\n\nWhen generating values, you may want to perform some side-effects.\n\n```haskell\nimport Control.Monad.IO.Class\nimport Control.Monad.Logger\nimport Data.Text\nimport Data.Text.IO\nimport Faker.ChuckNorris\n\nlogQuote :: (MonadIO m, MonadLogger m) =\u003e m ()\nlogQuote = do\n  userName \u003c- liftIO getLine\n  quote \u003c- generateNonDeterministic fact\n  $(logInfo) $ \"Chuck Norris\" userName quote\n```\n\nThis works fine for one-off generation - but if you try to repeatedly\ngenerate values, you will run into performance trouble.\n\n```haskell\nimport Control.Monad (replicateM)\n\nslowFunction :: (MonadIO m, MonadLogger m) =\u003e m ()\nslowFunction = replicateM 1000 logQuote\n```\n\nThis is because generating a `Fake` parses the data files and builds a\ncache for future use. Using the `Monad` instance on `Fake` shares that\ncache between `Fake`s, making faking fast. But in the above code, a\nnew `Fake` is generated each time - so the cache is discarded, and\nperformance is much worse.\n\nIt's better to use the `FakeT` monad transformer when writing such code,\nto get the benefits of sharing the cache, as well as being able to\nperform side effects. `FakeT` comes with the `mtl`-style `MonadFake`\nclass, for easy use with your monad stack, which lets you lift `Fake`s\nwith `liftFake`.\n\n```haskell\nimport Faker.Class\n\nbetterLogQuote :: (MonadIO m, MonadLogger m, MonadFake m) =\u003e m ()\nbetterLogQuote = do\n  userName \u003c- liftIO getLine\n  quote \u003c- liftFake fact\n  $(logInfo) $ \"Chuck Norris\" userName quote\n```\n\n`slowFunction` can be rewritten to be much faster, because the `FakeT`\nis shared between all the calls to `fact`.\n\n```haskell\nfastFunction :: (MonadIO m, MonadLogger m) =\u003e m ()\nfastFunction = generateNonDeterministic go\n  where\n    go :: FakeT m ()\n    go = replicateM 1000 logQuote\n```\n\n# Comparision with other libraries\n\nThere are two other libraries in the Hackage providing fake data:\n\n- [faker](https://hackage.haskell.org/package/faker-0.0.0.2)\n- [fake](https://hackage.haskell.org/package/fake-0.1.1.1)\n\nThe problem with both the above libraries is that the library covers\nonly a very small amount of fake data source. I wanted to have an\nequivalent functionality with something like [faker](https://github.com/stympy/faker). Also, most of\nthe combinators in this packages has been inspired (read as taken)\nfrom the `fake` library. Also, `fakedata` offers fairly good amount of\nsupport of different locales. Also since we rely on an external data\nsource, we get free updates and high quality data source with little\neffort. Also, it's easier to extend the library with [it's own data\nsource](https://github.com/psibi/fakedata/blob/master/Development.md#custom-fake-source-support-with-yml-file) if we want to do it that way.\n\n# Acknowledgments\n\nBenjamin Curtis for his [Ruby faker library](https://github.com/stympy/faker) from which the data\nsource is taken from.\n\nIcons made by [Freepik](https://www.flaticon.com/authors/freepik) from [Flaticon](https://www.flaticon.com/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffakedata-haskell%2Ffakedata","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffakedata-haskell%2Ffakedata","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffakedata-haskell%2Ffakedata/lists"}