{"action":"created","issue":{"url":"https://api.github.com/repos/CausalityLtd/ponyc/issues/336","labels_url":"https://api.github.com/repos/CausalityLtd/ponyc/issues/336/labels{/name}","comments_url":"https://api.github.com/repos/CausalityLtd/ponyc/issues/336/comments","events_url":"https://api.github.com/repos/CausalityLtd/ponyc/issues/336/events","html_url":"https://github.com/CausalityLtd/ponyc/issues/336","id":114418963,"number":336,"title":"Type Expressions and generic constraint checks","user":{"login":"darach","id":229042,"avatar_url":"https://avatars.githubusercontent.com/u/229042?v=3","gravatar_id":"","url":"https://api.github.com/users/darach","html_url":"https://github.com/darach","followers_url":"https://api.github.com/users/darach/followers","following_url":"https://api.github.com/users/darach/following{/other_user}","gists_url":"https://api.github.com/users/darach/gists{/gist_id}","starred_url":"https://api.github.com/users/darach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/darach/subscriptions","organizations_url":"https://api.github.com/users/darach/orgs","repos_url":"https://api.github.com/users/darach/repos","events_url":"https://api.github.com/users/darach/events{/privacy}","received_events_url":"https://api.github.com/users/darach/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-10-31T16:13:15Z","updated_at":"2015-11-06T13:15:00Z","closed_at":null,"body":"Tuples and possibly other type expressions don't seem to match up to the\r\nconstraint checks in generics:\r\n\r\n```\r\nclass X[A: Any #read]\r\n  new create(a: A) =>\r\n    None\r\n\r\nactor Y[A: Any #send]\r\n  new create(a: A) =>\r\n    None\r\n\r\nprimitive A\r\nprimitive B\r\nprimitive C\r\ntype Alphabet is ( A | B | C)\r\ntype StringThing is ( Alphabet , String )\r\n\r\nactor Main\r\n  new create(env : Env) =>\r\n    let t1 = X[String](\"foo\")\r\n    let t2 = X[Alphabet](A)\r\n    let t3 = X[StringThing]((A,\"foo\"))\r\n    let a1 = Y[String](\"foo\")\r\n    let a2 = Y[Alphabet](A)\r\n    let a3 = Y[StringThing]((A,\"foo\"))\r\n```\r\n\r\nThis results in an error for t3 and a3 above:\r\n\r\n```\r\n/Foo/bar.pony:19:15: type argument is outside its constraint\r\n    let t3 = X[StringThing]((A,\"foo\"))\r\n              ^\r\n/Foo/bar.pony:19:16: argument: ((A val | B val | C val), String val)\r\n    let t3 = X[StringThing]((A,\"foo\"))\r\n               ^\r\n/Foo/bar.pony:1:9: constraint: Any #read\r\nclass X[A: Any #read]\r\n        ^\r\n/Foo/bar.pony:22:15: type argument is outside its constraint\r\n    let a3 = Y[StringThing]((A,\"foo\"))\r\n              ^\r\n/Foo/bar.pony:22:16: argument: ((A val | B val | C val), String val)\r\n    let a3 = Y[StringThing]((A,\"foo\"))\r\n               ^\r\n/Foo/bar.pony:5:9: constraint: Any #send\r\nactor Y[A: Any #send]\r\n        ^\r\n```\r\n\r\nAs primitive and String default to val and the tuple itself is effectively a val shouldn't\r\nthe tuple be allowed in the class X and actor Y above? Is there a workaround?\r\n"},"comment":{"url":"https://api.github.com/repos/CausalityLtd/ponyc/issues/comments/154406286","html_url":"https://github.com/CausalityLtd/ponyc/issues/336#issuecomment-154406286","issue_url":"https://api.github.com/repos/CausalityLtd/ponyc/issues/336","id":154406286,"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-06T13:15:00Z","updated_at":"2015-11-06T13:15:00Z","body":"This is because a tuple in Pony is first class - it is not an object. The constraint `Any` says \"an object that provides these methods: oh wait, no methods\". A tuple provides no methods, but isn't an object.\r\n\r\nUnder the hood, a tuple is represented without an object indirection. That is, a tuple of (U32, U64) consumes 96 bits and has no object header.\r\n\r\nIn a generic, if something has no constraint at all, it will accept a tuple, like `Array[A]` does."}}