{"action":"created","issue":{"url":"https://api.github.com/repos/purescript/purescript/issues/2975","repository_url":"https://api.github.com/repos/purescript/purescript","labels_url":"https://api.github.com/repos/purescript/purescript/issues/2975/labels{/name}","comments_url":"https://api.github.com/repos/purescript/purescript/issues/2975/comments","events_url":"https://api.github.com/repos/purescript/purescript/issues/2975/events","html_url":"https://github.com/purescript/purescript/issues/2975","id":241190088,"node_id":"MDU6SXNzdWUyNDExOTAwODg=","number":2975,"title":"Improve errors for recursively-defined type class instances","user":{"login":"cdepillabout","id":64804,"node_id":"MDQ6VXNlcjY0ODA0","avatar_url":"https://avatars1.githubusercontent.com/u/64804?v=4","gravatar_id":"","url":"https://api.github.com/users/cdepillabout","html_url":"https://github.com/cdepillabout","followers_url":"https://api.github.com/users/cdepillabout/followers","following_url":"https://api.github.com/users/cdepillabout/following{/other_user}","gists_url":"https://api.github.com/users/cdepillabout/gists{/gist_id}","starred_url":"https://api.github.com/users/cdepillabout/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cdepillabout/subscriptions","organizations_url":"https://api.github.com/users/cdepillabout/orgs","repos_url":"https://api.github.com/users/cdepillabout/repos","events_url":"https://api.github.com/users/cdepillabout/events{/privacy}","received_events_url":"https://api.github.com/users/cdepillabout/received_events","type":"User","site_admin":false},"labels":[{"id":58678838,"node_id":"MDU6TGFiZWw1ODY3ODgzOA==","url":"https://api.github.com/repos/purescript/purescript/labels/enhancement","name":"enhancement","color":"84b6eb","default":true},{"id":178145312,"node_id":"MDU6TGFiZWwxNzgxNDUzMTI=","url":"https://api.github.com/repos/purescript/purescript/labels/error-message","name":"error-message","color":"f7c6c7","default":false},{"id":68227317,"node_id":"MDU6TGFiZWw2ODIyNzMxNw==","url":"https://api.github.com/repos/purescript/purescript/labels/typechecker","name":"typechecker","color":"009800","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/purescript/purescript/milestones/5","html_url":"https://github.com/purescript/purescript/milestone/5","labels_url":"https://api.github.com/repos/purescript/purescript/milestones/5/labels","id":533962,"node_id":"MDk6TWlsZXN0b25lNTMzOTYy","number":5,"title":"Approved","description":"Things which we have agreed we would like to implement at some point.\r\n\r\nFeel free to work on these, but please discuss them on #purescript IRC first.","creator":{"login":"paf31","id":630306,"node_id":"MDQ6VXNlcjYzMDMwNg==","avatar_url":"https://avatars0.githubusercontent.com/u/630306?v=4","gravatar_id":"","url":"https://api.github.com/users/paf31","html_url":"https://github.com/paf31","followers_url":"https://api.github.com/users/paf31/followers","following_url":"https://api.github.com/users/paf31/following{/other_user}","gists_url":"https://api.github.com/users/paf31/gists{/gist_id}","starred_url":"https://api.github.com/users/paf31/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paf31/subscriptions","organizations_url":"https://api.github.com/users/paf31/orgs","repos_url":"https://api.github.com/users/paf31/repos","events_url":"https://api.github.com/users/paf31/events{/privacy}","received_events_url":"https://api.github.com/users/paf31/received_events","type":"User","site_admin":false},"open_issues":75,"closed_issues":116,"state":"open","created_at":"2014-01-12T19:21:26Z","updated_at":"2018-09-06T09:18:32Z","due_on":null,"closed_at":null},"comments":13,"created_at":"2017-07-07T08:12:50Z","updated_at":"2018-10-16T19:52:59Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Given the following `Foo` type:\r\n\r\n```purescript\r\ndata Foo = Foo\r\n  { int :: Int\r\n  , foo :: Maybe Foo\r\n  }\r\n```\r\n\r\nI can derive `Generic` like the following:\r\n\r\n```purescript\r\nderive instance genericFoo :: Generic Foo _\r\n```\r\n\r\nI can even write an instance of `Eq` for `Foo` by hand:\r\n\r\n```purescript\r\ninstance eqFoo :: Eq Foo where\r\n  eq :: Foo -> Foo -> Boolean\r\n  eq (Foo fooA) (Foo fooB) =\r\n    fooA.int == fooB.int && fooA.foo == fooB.foo\r\n```\r\n\r\nHowever, I get an error when trying to use `genericEq` to write the `Eq` instance:\r\n\r\n```purescript\r\ninstance eqFoo :: Eq Foo where eq = genericEq\r\n```\r\n\r\nThe error is as follows:\r\n\r\n```\r\n[1/1 CycleInDeclaration] src/Web/Twitter/Test.purs:19:1\r\n\r\n  19  instance eqFoo :: Eq Foo where eq = genericEq\r\n      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n\r\n  The value of eqFoo is undefined here, so this reference is not allowed.\r\n```\r\n\r\n------------------------------------------------------------------------------------\r\n\r\nIs this a deficiency in the compiler?  Or simply a short-coming of `Generic`?  Or maybe just a limitation with recursive types in a strict language?\r\n\r\nIf this is a limitation with `Generic` and not a compiler issue, it would be nice to get a better error message from the compiler.  I didn't really understand what the error message was talking about until I played around with the code a little:\r\n\r\n> The value of eqFoo is undefined here, so this reference is not allowed.\r\n\r\nI mean, it makes sense now that I know what it is talking about, but it would have been more clear/obvious if it said something like:\r\n\r\n> It is not possible to use `genericEq` with `Foo` because `Foo` is a recursive datatype.\r\n\r\n--------------------------------------------------------------------------------------\r\n\r\nHere is a repository with some code to play around with if you want to reproduce the issue:\r\n\r\nhttps://github.com/cdepillabout/purescript-twitter-types/blob/16b5cfe7a55d1f23d12f6b87766abff31bf665ad/src/Web/Twitter/Test.purs"},"comment":{"url":"https://api.github.com/repos/purescript/purescript/issues/comments/430376565","html_url":"https://github.com/purescript/purescript/issues/2975#issuecomment-430376565","issue_url":"https://api.github.com/repos/purescript/purescript/issues/2975","id":430376565,"node_id":"MDEyOklzc3VlQ29tbWVudDQzMDM3NjU2NQ==","user":{"login":"nukisman","id":717051,"node_id":"MDQ6VXNlcjcxNzA1MQ==","avatar_url":"https://avatars3.githubusercontent.com/u/717051?v=4","gravatar_id":"","url":"https://api.github.com/users/nukisman","html_url":"https://github.com/nukisman","followers_url":"https://api.github.com/users/nukisman/followers","following_url":"https://api.github.com/users/nukisman/following{/other_user}","gists_url":"https://api.github.com/users/nukisman/gists{/gist_id}","starred_url":"https://api.github.com/users/nukisman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nukisman/subscriptions","organizations_url":"https://api.github.com/users/nukisman/orgs","repos_url":"https://api.github.com/users/nukisman/repos","events_url":"https://api.github.com/users/nukisman/events{/privacy}","received_events_url":"https://api.github.com/users/nukisman/received_events","type":"User","site_admin":false},"created_at":"2018-10-16T19:52:59Z","updated_at":"2018-10-16T19:52:59Z","author_association":"NONE","body":"Hi there!\r\nThere  is another example of the similar problem. \r\nI try to do exercise from the book: Ch7.Sec11.Ex1:\r\n```\r\nimport Prelude\r\nimport Data.Foldable (class Foldable, foldrDefault, foldMapDefaultL)\r\n\r\ndata Tree a\r\n  = Leaf\r\n  | Branch (Tree a) a (Tree a)\r\n\r\ninstance foldableTree :: Foldable Tree where\r\n  foldl _ acc Leaf = acc\r\n  foldl f acc (Branch l e r) = acc -- Just for debug\r\n  foldr = foldrDefault\r\n  foldMap = foldMapDefaultL\r\n```\r\nThe error is:\r\n`The value of foldableTree is undefined here, so this reference is not allowed.`\r\n\r\nShould I create a separate issue for it?\r\n"}}
{"actor":{"display_login":"nukisman"}}