{"action":"created","issue":{"url":"https://api.github.com/repos/purescript/purescript/issues/1686","labels_url":"https://api.github.com/repos/purescript/purescript/issues/1686/labels{/name}","comments_url":"https://api.github.com/repos/purescript/purescript/issues/1686/comments","events_url":"https://api.github.com/repos/purescript/purescript/issues/1686/events","html_url":"https://github.com/purescript/purescript/issues/1686","id":120140909,"number":1686,"title":"Why does compiler generate curried functions?","user":{"login":"dotneter-","id":3666289,"avatar_url":"https://avatars.githubusercontent.com/u/3666289?v=3","gravatar_id":"","url":"https://api.github.com/users/dotneter-","html_url":"https://github.com/dotneter-","followers_url":"https://api.github.com/users/dotneter-/followers","following_url":"https://api.github.com/users/dotneter-/following{/other_user}","gists_url":"https://api.github.com/users/dotneter-/gists{/gist_id}","starred_url":"https://api.github.com/users/dotneter-/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotneter-/subscriptions","organizations_url":"https://api.github.com/users/dotneter-/orgs","repos_url":"https://api.github.com/users/dotneter-/repos","events_url":"https://api.github.com/users/dotneter-/events{/privacy}","received_events_url":"https://api.github.com/users/dotneter-/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":44,"created_at":"2015-12-03T10:37:46Z","updated_at":"2015-12-03T16:21:46Z","closed_at":null,"body":"```\r\nfoo :: Int -> Int -> Int\r\nfoo x y = x + y\r\n\r\ntest :: Array Int -> Array Int\r\ntest = map (foo 1)\r\n\r\n```\r\n```\r\nvar foo = function (x) {\r\n    return function (y) {\r\n        return x + y | 0;\r\n    };\r\n};\r\n\r\nvar test = Prelude.map(Prelude.functorArray)(foo(1));\r\n```\r\nIt's bad for performance.\r\nWhy not just use ordinary js function and use currying when it's necessary?\r\n```\r\nvar foo = function (x, y) {\r\n        return x + y | 0;\r\n};\r\nvar test = Prelude.map(Prelude.functorArray)(function(x) {foo(1, x)});\r\n```\r\nPerformance-wise it's the same, you create a new function for every call.\r\nBut, for this code\r\n```\r\ntest2 :: Array Int -> Array Int\r\ntest2 = map (\\x -> (foo 1 x) * 2)\r\n```\r\ninstead of creating two functions\r\n```\r\nvar test2 = Prelude.map(Prelude.functorArray)(function (x) {\r\n    return foo(1)(x) * 2 | 0;\r\n});\r\n```\r\nyou need to create only one per call\r\n```\r\nvar test2 = Prelude.map(Prelude.functorArray)(function(x) {foo(1, x)*2});\r\n```\r\n\r\nand the most important part.\r\nwhen you don't need currying,\r\n```\r\ntest3 = foo 1 2\r\n```\r\ncompiler use a simple function call\r\n```\r\nvar test3 = foo(1, 2);\r\n```\r\ninstead of \r\n```\r\nvar test3 = foo(1)(2);\r\n```\r\nAlso, it would be easier to write ffi functions\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/purescript/purescript/issues/comments/161702328","html_url":"https://github.com/purescript/purescript/issues/1686#issuecomment-161702328","issue_url":"https://api.github.com/repos/purescript/purescript/issues/1686","id":161702328,"user":{"login":"natefaubion","id":144058,"avatar_url":"https://avatars.githubusercontent.com/u/144058?v=3","gravatar_id":"","url":"https://api.github.com/users/natefaubion","html_url":"https://github.com/natefaubion","followers_url":"https://api.github.com/users/natefaubion/followers","following_url":"https://api.github.com/users/natefaubion/following{/other_user}","gists_url":"https://api.github.com/users/natefaubion/gists{/gist_id}","starred_url":"https://api.github.com/users/natefaubion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/natefaubion/subscriptions","organizations_url":"https://api.github.com/users/natefaubion/orgs","repos_url":"https://api.github.com/users/natefaubion/repos","events_url":"https://api.github.com/users/natefaubion/events{/privacy}","received_events_url":"https://api.github.com/users/natefaubion/received_events","type":"User","site_admin":false},"created_at":"2015-12-03T16:21:46Z","updated_at":"2015-12-03T16:21:46Z","body":"> Shouldn't there be some side effect?\r\n\r\nOnly if you consider laziness a side effect. http://conal.net/blog/posts/elegant-memoization-with-functional-memo-tries A canonical example is using a lazy list for fibonacci numbers."}}