{"id":23739887,"url":"https://github.com/jharrilim/duckstruct","last_synced_at":"2025-07-21T10:02:42.763Z","repository":{"id":61232011,"uuid":"374147892","full_name":"jharrilim/duckstruct","owner":"jharrilim","description":"A strongly-typed duck-typed language. Solves type constraints on polymorphic functions and performs best-as-possible constant expression evaluation","archived":false,"fork":false,"pushed_at":"2024-11-21T02:18:12.000Z","size":342,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-05T11:03:57.161Z","etag":null,"topics":["compiler","constant-folding","duckstruct","partial-evaluation","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jharrilim.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-05T15:24:50.000Z","updated_at":"2025-01-15T19:10:35.000Z","dependencies_parsed_at":"2024-02-24T07:36:12.780Z","dependency_job_id":null,"html_url":"https://github.com/jharrilim/duckstruct","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jharrilim/duckstruct","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jharrilim%2Fduckstruct","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jharrilim%2Fduckstruct/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jharrilim%2Fduckstruct/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jharrilim%2Fduckstruct/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jharrilim","download_url":"https://codeload.github.com/jharrilim/duckstruct/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jharrilim%2Fduckstruct/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266278128,"owners_count":23904037,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compiler","constant-folding","duckstruct","partial-evaluation","rust"],"created_at":"2024-12-31T09:39:46.768Z","updated_at":"2025-07-21T10:02:42.742Z","avatar_url":"https://github.com/jharrilim.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Duckstruct\n\nDuckstruct is a language that aims to bring something new to the table: \"duck\nconstraints\" on function parameters. Duckstruct is able to infer what properties\nan object should respond to when passed into a function. For example, if you\nhave this function in Duckstruct:\n\n```\nf slope(coords) {\n  coords.x / coords.y\n}\n```\n\nDuckstruct is able to check at compile time that any object passed into the\n`slope` function must have an \"x\" property and a \"y\" property. This effectively\nallows your functions to be strongly typed in a structural manner, without the\nneed for concrete types.\n\nDuckstruct also considers all values known at compile-time to be concrete types.\nFor example, the type for a string, `\"a\"`, is actually `\"a\"` and not `string`.\nThis allows Duckstruct to unify these value types at compile-time for the sake\nof optimization, but also (ideally, in the future) to support IDE type hints\nthat can show both the value at any given point.\n\n## Thoughts\n\n- Type inference should be fairly similar to a regular\n[Hindley Milner Type System](https://en.wikipedia.org/wiki/Hindley%E2%80%93Milner_type_system),\nexcept instead of doing just type inference at a nominal level, Duckstruct will\nalso include values as types. Because of this, inference also has the effect of\nevaluating what actual values will be. This can be used for some easy\ncompile-time optimizations.\n\n- During type checking, we can build a graph which maps a computed value to each\nexpression, starting from the innermost expressions. This will give us a way to\ndetermine what each intermediate value is, which is particularly useful for code\nanalysis, ie. IDE inlay hints. We can also use this graph to simplify how we\ncompute the output. During evaluation traversal, we only need to traverse down\nto the highest computed value, and we can skip any nodes beneath that.\n\n- It will be easy for side effects to pollute type inference. The compiler\nshould provide a way to guard against this using a form of type-guard similar to\nthat of TypeScript's. Side effects meaning things that come from outside of the\nprogram. Those things we can't determine a \"value\" type for at compile time.\n\n- In C++, programmers [constexpr](https://en.cppreference.com/w/cpp/language/constexpr)\nall-the-things (ideally). We are essentially doing the same thing but for a\nlanguage without static types, and we're applying it ourselves in the compiler\ninstead of having developers write `constexpr`.\n\n- Turns out, there's a language called Idris which\n[seems to explore similar concepts to Duckstruct](http://docs.idris-lang.org/en/latest/tutorial/typesfuns.html#totality).\nThey deal with something they call totality, which from what I can tell, is\nthe handling of bounded/unbounded functions/loops.\n\n- Not having concrete types has the downside of not providing a clear way on how\nto document function parameters. A potential aide in that respect might be\na language service which can generate or update a comment with some type stubs\nbased on the inferred type.\n\n- The concepts explored here should be particularly useful to linters in dynamic\nlanguages such as Python or Javascript.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjharrilim%2Fduckstruct","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjharrilim%2Fduckstruct","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjharrilim%2Fduckstruct/lists"}