{"action":"created","issue":{"url":"https://api.github.com/repos/fscheck/FsCheck/issues/306","repository_url":"https://api.github.com/repos/fscheck/FsCheck","labels_url":"https://api.github.com/repos/fscheck/FsCheck/issues/306/labels{/name}","comments_url":"https://api.github.com/repos/fscheck/FsCheck/issues/306/comments","events_url":"https://api.github.com/repos/fscheck/FsCheck/issues/306/events","html_url":"https://github.com/fscheck/FsCheck/issues/306","id":174946605,"number":306,"title":"Generating values of provided types","user":{"login":"ploeh","id":242165,"avatar_url":"https://avatars.githubusercontent.com/u/242165?v=3","gravatar_id":"","url":"https://api.github.com/users/ploeh","html_url":"https://github.com/ploeh","followers_url":"https://api.github.com/users/ploeh/followers","following_url":"https://api.github.com/users/ploeh/following{/other_user}","gists_url":"https://api.github.com/users/ploeh/gists{/gist_id}","starred_url":"https://api.github.com/users/ploeh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ploeh/subscriptions","organizations_url":"https://api.github.com/users/ploeh/orgs","repos_url":"https://api.github.com/users/ploeh/repos","events_url":"https://api.github.com/users/ploeh/events{/privacy}","received_events_url":"https://api.github.com/users/ploeh/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-09-04T12:28:58Z","updated_at":"2016-09-05T08:40:25Z","closed_at":null,"body":"In F#, I can use the JSON type provider to define a type from a JSON document:\r\n\r\n```fsharp\r\nopen FSharp.Data\r\n\r\ntype Foo = JsonProvider<\"\"\"\r\n{\r\n    \"foo\": 42,\r\n    \"bar\": \"baz\"\r\n}\r\n\"\"\">\r\n```\r\n\r\nObviously, this is only a simple example. In reality, the JSON document could be much more complex.\r\n\r\nIt'd be nice to be able to ask FsCheck to generate values of such types:\r\n\r\n```fsharp\r\nopen FsCheck\r\n\r\nlet ``An intance of Foo can't be automatically generated`` () =\r\n    Arb.from<Foo.Root>\r\n    |> Prop.forAll <| ignore\r\n    |> Check.QuickThrowOnFailure\r\n```\r\n\r\nUnfortunately, this doesn't work:\r\n\r\n```\r\nSystem.Exception :\r\nThe type FSharp.Data.Runtime.BaseTypes.IJsonDocument is not handled automatically\r\nby FsCheck. Consider using another type or writing and registering a generator for it.\r\n```\r\n\r\nClearly, it's possible to overcome this problem by explicitly defining a generator:\r\n\r\n```fsharp\r\nlet ``An instance can be created`` () =\r\n    gen {\r\n        let! foo = Arb.generate<int>\r\n        let! bar = Arb.generate<string>\r\n        return Foo.Root (foo, bar) }\r\n    |> Arb.fromGen\r\n    |> Prop.forAll <| ignore\r\n    |> Check.QuickThrowOnFailure\r\n```\r\n\r\nThis works for this toy example, but if the JSON document is big and complicated, it'd require considerable maintenance.\r\n\r\nIt'd be nice if this 'just worked'. The same with the XML provider, for that matter.\r\n\r\nCan anything be done about this?\r\n\r\nI'll be happy to submit a pull request if this is something that seems possible and desirable, but I thought I'd ask here before starting investigation."},"comment":{"url":"https://api.github.com/repos/fscheck/FsCheck/issues/comments/244690894","html_url":"https://github.com/fscheck/FsCheck/issues/306#issuecomment-244690894","issue_url":"https://api.github.com/repos/fscheck/FsCheck/issues/306","id":244690894,"user":{"login":"moodmosaic","id":287532,"avatar_url":"https://avatars.githubusercontent.com/u/287532?v=3","gravatar_id":"","url":"https://api.github.com/users/moodmosaic","html_url":"https://github.com/moodmosaic","followers_url":"https://api.github.com/users/moodmosaic/followers","following_url":"https://api.github.com/users/moodmosaic/following{/other_user}","gists_url":"https://api.github.com/users/moodmosaic/gists{/gist_id}","starred_url":"https://api.github.com/users/moodmosaic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/moodmosaic/subscriptions","organizations_url":"https://api.github.com/users/moodmosaic/orgs","repos_url":"https://api.github.com/users/moodmosaic/repos","events_url":"https://api.github.com/users/moodmosaic/events{/privacy}","received_events_url":"https://api.github.com/users/moodmosaic/received_events","type":"User","site_admin":false},"created_at":"2016-09-05T08:40:25Z","updated_at":"2016-09-05T08:40:25Z","body":">I would be very happy to start curating a set of projects with Arbitrary instances for other libraries under the FsCheck organization though.\r\n\r\nNot a bad idea at all; they do similar in Haskell ([servant-quickcheck](https://hackage.haskell.org/package/servant-quickcheck), [tasty-quickcheck](https://hackage.haskell.org/package/tasty-quickcheck), [quickcheck-regex](https://hackage.haskell.org/package/quickcheck-regex), and more).\r\n\r\nIn fact, if it's not simple, tricks for creating gen/shrink pairs out of erased types could live on a separate project as well."}}
{"actor":{"display_login":"moodmosaic"}}