{"action":"created","issue":{"url":"https://api.github.com/repos/dreixel/generic-deriving/issues/17","labels_url":"https://api.github.com/repos/dreixel/generic-deriving/issues/17/labels{/name}","comments_url":"https://api.github.com/repos/dreixel/generic-deriving/issues/17/comments","events_url":"https://api.github.com/repos/dreixel/generic-deriving/issues/17/events","html_url":"https://github.com/dreixel/generic-deriving/pull/17","id":92144383,"number":17,"title":"Allow TH generation of data types with infix constructors","user":{"login":"RyanGlScott","id":2364661,"avatar_url":"https://avatars.githubusercontent.com/u/2364661?v=3","gravatar_id":"","url":"https://api.github.com/users/RyanGlScott","html_url":"https://github.com/RyanGlScott","followers_url":"https://api.github.com/users/RyanGlScott/followers","following_url":"https://api.github.com/users/RyanGlScott/following{/other_user}","gists_url":"https://api.github.com/users/RyanGlScott/gists{/gist_id}","starred_url":"https://api.github.com/users/RyanGlScott/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RyanGlScott/subscriptions","organizations_url":"https://api.github.com/users/RyanGlScott/orgs","repos_url":"https://api.github.com/users/RyanGlScott/repos","events_url":"https://api.github.com/users/RyanGlScott/events{/privacy}","received_events_url":"https://api.github.com/users/RyanGlScott/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-06-30T16:58:28Z","updated_at":"2015-07-01T14:06:36Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/dreixel/generic-deriving/pulls/17","html_url":"https://github.com/dreixel/generic-deriving/pull/17","diff_url":"https://github.com/dreixel/generic-deriving/pull/17.diff","patch_url":"https://github.com/dreixel/generic-deriving/pull/17.patch"},"body":"Currently, the Template Haskell mechanism for deriving `Generic` doesn't work correctly for data types with infix constructors. For example, if you have this:\r\n\r\n```haskell\r\ndata Infix a b = a :?: b\r\n$(deriveAll ''Infix)\r\n```\r\n\r\nThen `deriveAll` would attempt to define `data Infix_:?:_`, which Template Haskell rejects.\r\n\r\nTo get around this, I use a trick from [`genifunctors`](https://github.com/danr/genifunctors/blob/4677bb57423b1b380ce9b50cc3d765a5c49a957a/Data/Generics/Genifunctors.hs#L272-278) and sanitize each `nameBase` before being used in a type name. Non-alphanumeric characters are replaced by their ASCII codes, so the above example would generate `data NInfix_N_58_63_58_` instead.\r\n\r\nSince this changes the names of generated identifiers, I had to make some changes to `Examples.hs` to make it work again."},"comment":{"url":"https://api.github.com/repos/dreixel/generic-deriving/issues/comments/117687034","html_url":"https://github.com/dreixel/generic-deriving/pull/17#issuecomment-117687034","issue_url":"https://api.github.com/repos/dreixel/generic-deriving/issues/17","id":117687034,"user":{"login":"RyanGlScott","id":2364661,"avatar_url":"https://avatars.githubusercontent.com/u/2364661?v=3","gravatar_id":"","url":"https://api.github.com/users/RyanGlScott","html_url":"https://github.com/RyanGlScott","followers_url":"https://api.github.com/users/RyanGlScott/followers","following_url":"https://api.github.com/users/RyanGlScott/following{/other_user}","gists_url":"https://api.github.com/users/RyanGlScott/gists{/gist_id}","starred_url":"https://api.github.com/users/RyanGlScott/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RyanGlScott/subscriptions","organizations_url":"https://api.github.com/users/RyanGlScott/orgs","repos_url":"https://api.github.com/users/RyanGlScott/repos","events_url":"https://api.github.com/users/RyanGlScott/events{/privacy}","received_events_url":"https://api.github.com/users/RyanGlScott/received_events","type":"User","site_admin":false},"created_at":"2015-07-01T14:06:36Z","updated_at":"2015-07-01T14:06:36Z","body":"Oh, that. I didn't make any changes to the Uniplate-related code. The [original usage](https://github.com/dreixel/generic-deriving/blob/bb6fa2a31481cf5935a8ff1c388959fdeeb25755/examples/Examples.hs#L98-104) of `transformdefault` in the `Example.hs` file was this:\r\n\r\n```haskell\r\ninstance Uniplate Tree where\r\n    ...\r\n    transform = transformdefault\r\n    transformM = transformdefault\r\n```\r\n\r\nbut `transformM = transformdefault` gives a compilation error:\r\n\r\n```\r\n    Couldn't match expected type `m Tree' with actual type `Tree'\r\n    Expected type: (Tree -> m Tree) -> Tree -> m Tree\r\n      Actual type: (Tree -> Tree) -> Tree -> Tree\r\n    In the expression: transformdefault\r\n    In an equation for `transformM': transformM = transformdefault\r\n```\r\n\r\nI presumed this was a typo and changed `transformM = transformdefault` to `transformM = transformMdefault`, which seemed to make the examples work on GHC 7.0 (I could be wrong though)."}}