{"action":"created","issue":{"url":"https://api.github.com/repos/CausalityLtd/ponyc/issues/351","labels_url":"https://api.github.com/repos/CausalityLtd/ponyc/issues/351/labels{/name}","comments_url":"https://api.github.com/repos/CausalityLtd/ponyc/issues/351/comments","events_url":"https://api.github.com/repos/CausalityLtd/ponyc/issues/351/events","html_url":"https://github.com/CausalityLtd/ponyc/issues/351","id":115498887,"number":351,"title":"Function syntax for pattern matching","user":{"login":"sylvanc","id":2785007,"avatar_url":"https://avatars.githubusercontent.com/u/2785007?v=3","gravatar_id":"","url":"https://api.github.com/users/sylvanc","html_url":"https://github.com/sylvanc","followers_url":"https://api.github.com/users/sylvanc/followers","following_url":"https://api.github.com/users/sylvanc/following{/other_user}","gists_url":"https://api.github.com/users/sylvanc/gists{/gist_id}","starred_url":"https://api.github.com/users/sylvanc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sylvanc/subscriptions","organizations_url":"https://api.github.com/users/sylvanc/orgs","repos_url":"https://api.github.com/users/sylvanc/repos","events_url":"https://api.github.com/users/sylvanc/events{/privacy}","received_events_url":"https://api.github.com/users/sylvanc/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/CausalityLtd/ponyc/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/CausalityLtd/ponyc/labels/medium","name":"medium","color":"fbca04"}],"state":"open","locked":false,"assignee":{"login":"andymcn","id":7050628,"avatar_url":"https://avatars.githubusercontent.com/u/7050628?v=3","gravatar_id":"","url":"https://api.github.com/users/andymcn","html_url":"https://github.com/andymcn","followers_url":"https://api.github.com/users/andymcn/followers","following_url":"https://api.github.com/users/andymcn/following{/other_user}","gists_url":"https://api.github.com/users/andymcn/gists{/gist_id}","starred_url":"https://api.github.com/users/andymcn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andymcn/subscriptions","organizations_url":"https://api.github.com/users/andymcn/orgs","repos_url":"https://api.github.com/users/andymcn/repos","events_url":"https://api.github.com/users/andymcn/events{/privacy}","received_events_url":"https://api.github.com/users/andymcn/received_events","type":"User","site_admin":false},"milestone":null,"comments":28,"created_at":"2015-11-06T12:47:57Z","updated_at":"2015-11-26T11:06:42Z","closed_at":null,"body":"This is probably best illustrated with an example. Right now, we can write:\r\n\r\n```\r\nprimitive Fibonacci\r\n  fun apply(x: U64): U64 =>\r\n    match x\r\n    | 0 => 0\r\n    | 1 => 1\r\n    else Fibonacci(x - 1) + Fibonacci(x - 2)\r\n    end\r\n```\r\n\r\nWhat we want to be able to write is:\r\n\r\n```\r\nprimitive Fibonacci\r\n  fun apply(0): U64 => 0\r\n  fun apply(1): U64 => 1\r\n  fun apply(x: U64): U64 => Fibonnaci(x - 1) + Fibonacci(x - 2)\r\n```\r\n\r\nAs with all enhancement issues, comments are encouraged! @andymcn will be implementing this. So far it looks like we can do it with sugaring to a match expression, allowing us to keep a single entry in the vtable, to that at runtime, types don't have to be evaluated to do dispatch (which is important).\r\n"},"comment":{"url":"https://api.github.com/repos/CausalityLtd/ponyc/issues/comments/159883607","html_url":"https://github.com/CausalityLtd/ponyc/issues/351#issuecomment-159883607","issue_url":"https://api.github.com/repos/CausalityLtd/ponyc/issues/351","id":159883607,"user":{"login":"sylvanc","id":2785007,"avatar_url":"https://avatars.githubusercontent.com/u/2785007?v=3","gravatar_id":"","url":"https://api.github.com/users/sylvanc","html_url":"https://github.com/sylvanc","followers_url":"https://api.github.com/users/sylvanc/followers","following_url":"https://api.github.com/users/sylvanc/following{/other_user}","gists_url":"https://api.github.com/users/sylvanc/gists{/gist_id}","starred_url":"https://api.github.com/users/sylvanc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sylvanc/subscriptions","organizations_url":"https://api.github.com/users/sylvanc/orgs","repos_url":"https://api.github.com/users/sylvanc/repos","events_url":"https://api.github.com/users/sylvanc/events{/privacy}","received_events_url":"https://api.github.com/users/sylvanc/received_events","type":"User","site_admin":false},"created_at":"2015-11-26T11:06:42Z","updated_at":"2015-11-26T11:06:42Z","body":"In fact, based on #406, it can be:\r\n\r\n```pony\r\nfun foo(x: U64, y: U64): Bool if x > y => true\r\n```\r\n\r\nWhich I think is even nicer."}}