{"id":13837506,"url":"https://github.com/andreaslyn/mini-yu","last_synced_at":"2025-07-10T18:33:30.662Z","repository":{"id":56657197,"uuid":"306376894","full_name":"andreaslyn/mini-yu","owner":"andreaslyn","description":"A dependently typed programming language prototype","archived":false,"fork":false,"pushed_at":"2024-03-28T20:52:06.000Z","size":959,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-03-28T21:54:16.026Z","etag":null,"topics":["compiler","dependent-types","functional-programming","programming-language","type-theory"],"latest_commit_sha":null,"homepage":"","language":"Haskell","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/andreaslyn.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":"2020-10-22T15:14:18.000Z","updated_at":"2024-05-30T04:34:41.563Z","dependencies_parsed_at":"2024-05-30T04:34:37.707Z","dependency_job_id":"3d2c1450-6806-4d55-af8f-7ce25198c024","html_url":"https://github.com/andreaslyn/mini-yu","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/andreaslyn/mini-yu","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreaslyn%2Fmini-yu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreaslyn%2Fmini-yu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreaslyn%2Fmini-yu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreaslyn%2Fmini-yu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andreaslyn","download_url":"https://codeload.github.com/andreaslyn/mini-yu/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreaslyn%2Fmini-yu/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264631212,"owners_count":23640941,"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","dependent-types","functional-programming","programming-language","type-theory"],"created_at":"2024-08-04T15:01:12.027Z","updated_at":"2025-07-10T18:33:30.091Z","avatar_url":"https://github.com/andreaslyn.png","language":"Haskell","funding_links":[],"categories":["Haskell"],"sub_categories":[],"readme":"# Mini Yu\n\nMini Yu is a dependently typed programming language, similar to Agda, Idris, Coq, Lean.\nIt is an experimental language to test dependently typed language\nfeatures and runtime implementation.\n\nThe mini yu compiler is implemented in Haskell. It compiles mini yu source code to\nC code, which is further compiled to machine code with gcc. Mini Yu uses reference counting\nas garbage collection strategy, inspired by [Lean 4](https://github.com/leanprover/lean4)\nand [Koka](https://github.com/koka-lang/koka).\n\n# Related Work\n\nA list of some work I have relied on while developing mini yu:\n* [Sebastian Ullrich and Leonardo de Moura, Counting Immutable Beans: Reference Counting Optimized for Purely Functional Programming](https://arxiv.org/abs/1908.05647)\n* [Jesper Cockx, Dependent pattern matching and proof-relevant unification](https://jesper.sikanda.be/files/thesis-final-digital.pdf)\n* [Andreas Abel, foetus - Termination Checker for Simple Functional Programs](https://www.semanticscholar.org/paper/foetus-Termination-Checker-for-Simple-Functional-Abel/c216d842401569de47d2472b84d33f4f38bbe670)\n* [Matúš Tejiščák and Edwin Brady, Practical Erasure in Dependently Typed Languages](https://eb.host.cs.st-andrews.ac.uk/drafts/dtp-erasure-draft.pdf)\n* [Daan Leijen, Benjamin Zorn and Leonardo de Moura, Mimalloc: Free List Sharding in Action](https://www.microsoft.com/en-us/research/publication/mimalloc-free-list-sharding-in-action/)\n* [KC Sivaramakrishnan et al, Retrofitting Effect Handlers onto OCaml](https://dl.acm.org/doi/10.1145/3408995)\n\n# Building\n\nIn order to build the mini yu source code, you need to be running on\na Unix system, Mac, Linux, FreeBSD, etc.\n\nBefore building, make sure you have [stack](https://docs.haskellstack.org/en/stable/README/)\ninstalled on the system. You can obtain version\nof stack with the command\n```\nstack --version\n```\nIf you have an old version of stack, then you may need to\nupgrade it. This can commonly be achieved with the command\n```\nstack upgrade\n```\nTo build mini yu quickly, go to the project root and enter the commands\n```\ngit submodule update --init\nmake config\nmake SPLITSTACK=0\nmake stdlib\n```\nThis will clone the [mimalloc](https://github.com/microsoft/mimalloc)\nsubmodule, which mini yu uses as memory allocator. The `make` commands\nwill configure and build the project. The `SPLITSTACK=0` option disables\na split stack feature used for automatically growing/shrinking the\nruntime stack(s). This feature requires a custom gcc version. The `stdlib`\ntarget builds the Mini Yu standard library.\n\nIn order to build mini yu with split stack feature, make sure you have MP 4.2+\nand MPFR 3.1.0+ and MPC 0.8.0+ installed, then issue the following commands:\n```\ngit submodule update --init\nmake config\nmake -j8 custom-gcc\nmake\nmake stdlib\n```\nThis will build mimalloc, the custom version of gcc, and the mini yu\ncompiler. Beware that building the custom gcc will take some time.\n\nWhen the build has finished, the `yuc` executable in the project root\ncan be used to compile mini yu source code. The next section describes\nhow to get started.\n\n# Features\n\nThis section describes some of the features of Mini Yu.\n\n## Hello World and effects\n\nTo get started, here is the Hello World program in Mini Yu:\n```\n## Import basic functionality from standard library:\nimport yu/prelude\nof (...)\n\n## Function main is the program entry point:\nval main : {} -\u003e\u003e {}\nlet () =\u003e \"Hello, World!\" .println\n```\nNote that line comments start with `##`.\n\nCopy the code and put it in a file named `hello-world.yu`.\nCompile it with the command\n```\npath/to/yuc hello-world.yu -c -o\n```\nThe `-c` command line argument tells mini yu to compile the program,\nnot just type check. The `-o` command line argument tells\nmini yu to optimize the program. This will produce a binary\nfile called `hello-world.yu.exe`, which prints `Hello, World!`\nwhen executed.\n\nThe type of `main` is effectful function type `{} -\u003e\u003e {}`, which is\nindicating that the `main` function has one argument of type unit `{}`, is\neffectful `-\u003e\u003e`, and codomain (return type) is unit `{}`.\nThe effectful arrow type `-\u003e\u003e` allows us to apply the `.println`\npostfix operator and print `Hello, World!` to the standard output device.\n\nCurrently, the only supported effect is `-\u003e\u003e`, which allows printing\nstrings to standard out. I am working on extending mini yu with a\nmore powerful effect system.\n\nAn effect system is used to control where observable side effects may\noccur. The pure function type `-\u003e` is used for functions which do not\nhave side effects. Hence, we cannot print from inside such a function.\nMini Yu will not accept the following program\n```\nimport yu/prelude\nof (...)\n\nval customPrint : Str -\u003e {}\nlet s =\u003e s .println\n\nval main : {} -\u003e\u003e {}\nlet () =\u003e customPrint \"Hello, World\"\n```\nChange the type of `customPrint` to `Str -\u003e\u003e {}`, and then it will work.\n\n## Algebraic data types\n\nMini Yu has algebraic data types. For example, the natural numbers can be defined with\n```\ndata Nat : Ty\nof 0 : Nat\nof succ : Nat -\u003e Nat\n```\n**Note that the examples may not type check if you import files\nfrom the standard library at the same time, because of name\nclashes with the standard library.**\n\nThe identity type can be defined with\n```\ndata Id [A] : A \u0026 A -\u003e Ty\nof refl [A] [a : A] : Id a a\n```\nThe square brackets mark implicit arguments `[A : Ty]` and `[a : A]`,\nand `A \u0026 A -\u003e Ty` is a binary function type.\n\n## Dependent pattern matching\n\nValues are declared with `val` and defined by (dependent) pattern matching.\nAddition on natural numbers can be defined by\n```\nval plus : Nat \u0026 Nat -\u003e Nat\nlet m 0 =\u003e m\nlet m (succ n) =\u003e succ (plus m n)\n```\nAnd transitivity of identity\n```\nval trans [A] [x y z : A] : Id x y \u0026 Id y z -\u003e Id x z\nlet refl p =\u003e p\n```\n\n## Operator overloading\n\nMini Yu supports definition and overloading of operators.\nThere are 3 kinds of operators:\n* prefix operators,\n* infix operators,\n* postfix operators.\n\nPrefix and infix operators start with an operator symbol, such as `+`,\n`\u0026`, `!`, `=`, etc. But the symbols `\\` and `#` are treated\nspecially, not regarded as operator symbols. Postfix operators\nstart with a period `.` for example `.length`, `.is-true?`.\nVariable identifiers start with an alphanumeric character,\nsuch as `A`, `1st`, `a*b`. Note that if we insert space `a * b`,\nthen it will mean the infix operator `*` applied to two arguments,\n`a` and `b`, rather than the variable `a*b`.\n\nWe can define the natural numbers by using a prefix operator `++` for\nthe successor constructor,\n```\ndata Nat : Ty\nof 0 : Nat\nof (++#Nat) : Nat -\u003e Nat\n```\nThe `#Nat` is indicating that this is the operator `++` for `Nat`.\n\nNow define `1` and `2` by\n```\nval 1 : Nat\nlet =\u003e ++ 0\n\nval 2 : Nat\nlet =\u003e ++ 1\n```\n\nAddition on natural numbers as infix operator `+`,\n```\nval (+#Nat) : Nat \u0026 Nat -\u003e Nat\nlet m 0 =\u003e m\nlet m (++ n) =\u003e ++ (m + n)\n```\n\nA `.is-even?` postfix operator on natural numbers,\n```\nval (.is-even?#Nat) : Nat -\u003e Bool\nlet 0 =\u003e true\nlet (++ 0) =\u003e false\nlet (++ ++ n) =\u003e n .is-even?\n```\nwhere `Bool` is the type\n```\ndata Bool : Ty\nof false : Bool\nof true : Bool\n```\n\nWe can overload operators based on type of an argument.\nIt is possible to define addition of booleans by\n```\nval (+#Bool) : Bool \u0026 Bool -\u003e Bool\nlet true b =\u003e true\nlet false b =\u003e b\n```\nFor left associative infix operators, such as `+`, mini yu uses the\ntype of the first argument to determine which operator to apply. So\n`true + x` applies `+#Bool` and `1 + y` applies `+#Nat`.\n\n### Details on operator precedence\n\nThe associativity and operator precedence of infix operators is given\nby the first operator symbol. The infix operator precedence table is:\n```\n^ @        (right associative)\n* / %      (left associative)\n$ | \u0026      (right associative)\n+ -        (left associative)\n= : ? !    (right associative)\n\u003c \u003e ~      (left associative)\n```\nThe operators in the top have higher precedence than those in the\nbottom, so infix `+` is left associative and has lower precedence\nthan infix `*`.\n\nFor right associative operators, mini yu uses the second argument to\ndetermine which operator to apply, and the type of the first argument\nof both prefix and postfix operators is used by mini yu to determine\nwhich operator to apply.\n\nNote that these associativity and precedence rules do no apply to the\nfew built-in operators, such as `=\u003e`, `-\u003e` and `:`. For example\nfunction type `-\u003e` has lower precedence than infix `\u003c`, and `-\u003e` is\nright associative.\n\n## Lazy evaluation\n\nBy default, mini yu evaluates function arguments eagerly, but it is\npossible to mark arguments as lazy. For example, in the definition of\naddition of booleans, it is often desired to have the second argument\nevaluated only when the first argument is false. This can be achieved with\n```\nval (+#Bool) : Bool \u0026 ([] -\u003e Bool) -\u003e Bool\nlet true b =\u003e true\nlet false b =\u003e b []\n```\nThe type `[] -\u003e Bool` is the lazy `Bool` type. The operator `+#Bool`\nevaluates the second argument only when the first argument is `false`.\n\n## Delayed evaluation\n\nDelayed evaluation is similar to lazy evaluation, but it will\nnot memoize its result, like lazy does. The below definition of\n`Bool` product demonstrates delayed evaluation.\n```\nval (*#Bool) : Bool \u0026 (() -\u003e Bool) -\u003e Bool\nlet false b =\u003e false\nlet true b =\u003e b ()\n```\n\n## Dependent types\n\nDefine the vector data type by\n```\ndata Vec : Nat \u0026 Ty -\u003e Ty\nof nilv [A] : Vec 0 A\nof (::#Vec) [A n] : A \u0026 Vec n A -\u003e Vec (++ n) A\n```\nNote that infix `::` is right associative, so it overloads on the\nsecond argument, which is `Vec` in this case.\n\nAs demonstrated earlier, mini yu supports dependent implicit arguments.\nFor an example of a dependent (explicit) arguments we define a (dependent)\nfunction which returns the zero vector of any length `n`, where the\ncodomain of the function `Vec n Nat` depends on `n`:\n```\nval 0v : (n : Nat) -\u003e Vec n Nat\nlet 0 =\u003e nilv\nlet (++ n) =\u003e 0 :: 0v n\n```\n\n## Importing and standard library\n\nMini Yu comes with a standard library with some basic functionality.\nFor example, to import the list type, one can write\n```\nimport yu/List\nof List\nof nil\nof (...#List)\n```\nThis puts `List` and `nil` into scope, and `(...#List)` all operators\non `List` from the module `yu/List`. One can specify an aliases for\nmodules with\n```\nimport L =\u003e yu/List\nof List\nof (...#List)\n```\nThis puts `List` and it's operators into scope, and we can use `nil.L`\nto refer to `nil` from module `yu/List`. In general `x.L` will refer\n`x` from module `yu/List`.\n\nAlternatively, use `(...)` to import everything from the module\n```\nimport yu/List\nof (...)\n```\n\nTake a look at the `stdlib/yu/` directory to see what is available\nin the standard library. If an import string starts with `yu/`, such\nas `yu/List`, then mini yu will search for files in the standard\nlibrary.\n\nUsers can specify custom packages with the `-p` command line option.\nFor example if we have a directory `path/to/package`, then we\ncan invoke `yuc` with `-p path/to/package`, which will bring\nmodules with `package/` prefix into scope. One can imagine a file\ncalled `path/to/package/mod.yu`, consisting of\n```\nimport yu/Nat\nof Nat\n\nimport L =\u003e yu/List\nof List\n\nval empty : List Nat\nlet =\u003e nil.L\n```\nBy running `yuc` with `yuc main.yu -c -p path/to/package`, then\nwe can refer to the module with `package/mod`. For example, in `main.yu`\ncontaining\n```\nimport yu/prelude\nof (...)\n\nimport M =\u003e package/mod\n\nval main : {} -\u003e\u003e {}\nlet () =\u003e empty.M .len .println\n```\nThis program will print `0` when executed.\n\n## More examples\n\nFor more examples, take a look at the `examples/` directory\nand the `stdlib/yu/` directory, implementing the standard library.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreaslyn%2Fmini-yu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandreaslyn%2Fmini-yu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreaslyn%2Fmini-yu/lists"}