{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/flow/issues/838","labels_url":"https://api.github.com/repos/facebook/flow/issues/838/labels{/name}","comments_url":"https://api.github.com/repos/facebook/flow/issues/838/comments","events_url":"https://api.github.com/repos/facebook/flow/issues/838/events","html_url":"https://github.com/facebook/flow/issues/838","id":107570704,"number":838,"title":"Please allow defining types separate from implementations","user":{"login":"Gozala","id":21236,"avatar_url":"https://avatars.githubusercontent.com/u/21236?v=3","gravatar_id":"","url":"https://api.github.com/users/Gozala","html_url":"https://github.com/Gozala","followers_url":"https://api.github.com/users/Gozala/followers","following_url":"https://api.github.com/users/Gozala/following{/other_user}","gists_url":"https://api.github.com/users/Gozala/gists{/gist_id}","starred_url":"https://api.github.com/users/Gozala/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gozala/subscriptions","organizations_url":"https://api.github.com/users/Gozala/orgs","repos_url":"https://api.github.com/users/Gozala/repos","events_url":"https://api.github.com/users/Gozala/events{/privacy}","received_events_url":"https://api.github.com/users/Gozala/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":18,"created_at":"2015-09-21T18:28:07Z","updated_at":"2015-10-15T17:31:27Z","closed_at":null,"body":"I constantly find myself wishing I could define types separately from their implementations kind of like you do it in haskell. Unfortunately now type declarations for same named functions are completely dropped see #748 \r\n\r\nI would like to illustrate it in the example:\r\n\r\n```js\r\nimport {html, forward, Effects} from \"reflex\";\r\nimport type {Task, Update, View} from \"reflex\";\r\n\r\ntype Model = {value: number};\r\n\r\ntype init = () => Model;\r\nexport var init = () => {value: 0};\r\n\r\ntype Increment = {type: 'Increment'};\r\ntype Decrement = {type: 'Decrement'};\r\ntype Action \r\n  = Increment\r\n  | Decrement;\r\n\r\n\r\ntype inc = () => Increment;\r\nexport var inc = () => {type: 'Increment'};\r\n\r\ntype dec = () => Decrement;\r\nexport var dec = () => {type: 'Decrement'};\r\n\r\ntype update = Update<Model, Action>;\r\n// Imported Update has following type signature:\r\n// type Update <Model, Action> = (Model, Action) => [Model, Task<Never, Action>]\r\n\r\nexport var update = (model, action) =>\r\n  action instanceof Increment ?\r\n    [set('x', model.x + 1, model), Effects.none] :\r\n  action instanceof Decrement ?\r\n    [set('x', model.x - 1, model), Effects.none] :\r\n    [model, Effects.none];\r\n\r\n// View\r\ntype view = View<[Model, Address<Action>]>;\r\n\r\n// Where View has following type:\r\n// type View <Args> = (...Args) => VirtualElement;\r\nexport var view = (model, address) => {\r\n  return html.span({key: 'counter'}, [\r\n    html.button({\r\n      key: 'decrement',\r\n      onClick: forward(Decrement, address)\r\n    }, [\"-\"]),\r\n    html.span({\r\n      key: 'value'\r\n    }, [String(model.value)]),\r\n    html.button({\r\n      key: 'increment',\r\n      onClick: forward(Increment, address)\r\n    }, [\"+\"])\r\n  ]);\r\n};\r\n```\r\n\r\nInteresting parts are `Update` and `View` imported type, that were used to create type definitions for `update` and `view` functions. I find it a lot more handy than and clear than annotating individual functions. I also find it a lot more convenient to be able to annotate things without changing them in place. Note that I also have dropped mandatory argument names in the function type definitions which I find redundant when defining types separately."},"comment":{"url":"https://api.github.com/repos/facebook/flow/issues/comments/148466780","html_url":"https://github.com/facebook/flow/issues/838#issuecomment-148466780","issue_url":"https://api.github.com/repos/facebook/flow/issues/838","id":148466780,"user":{"login":"Gozala","id":21236,"avatar_url":"https://avatars.githubusercontent.com/u/21236?v=3","gravatar_id":"","url":"https://api.github.com/users/Gozala","html_url":"https://github.com/Gozala","followers_url":"https://api.github.com/users/Gozala/followers","following_url":"https://api.github.com/users/Gozala/following{/other_user}","gists_url":"https://api.github.com/users/Gozala/gists{/gist_id}","starred_url":"https://api.github.com/users/Gozala/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gozala/subscriptions","organizations_url":"https://api.github.com/users/Gozala/orgs","repos_url":"https://api.github.com/users/Gozala/repos","events_url":"https://api.github.com/users/Gozala/events{/privacy}","received_events_url":"https://api.github.com/users/Gozala/received_events","type":"User","site_admin":false},"created_at":"2015-10-15T17:31:27Z","updated_at":"2015-10-15T17:31:27Z","body":"@gyzerok BTW in flow `Number` and `number` are different types see (http://flowtype.org/docs/quick-reference.html#the-number-constructor). Your examples seem to refer to `number`."}}