{"id":13783102,"url":"https://github.com/pqnelson/ml","last_synced_at":"2025-05-11T17:30:53.498Z","repository":{"id":149593694,"uuid":"156584134","full_name":"pqnelson/ml","owner":"pqnelson","description":"A Study in Implementing Functional Programming Languages","archived":false,"fork":false,"pushed_at":"2019-08-17T18:30:56.000Z","size":106,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-08-03T18:18:15.759Z","etag":null,"topics":["abstract-machine","acsl","c","compiler","correctness","functional-programming-language","hoare-logic","interpreter","language","parser","twelf"],"latest_commit_sha":null,"homepage":null,"language":"C","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/pqnelson.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}},"created_at":"2018-11-07T17:31:38.000Z","updated_at":"2024-04-06T13:39:06.000Z","dependencies_parsed_at":"2024-01-07T23:10:12.037Z","dependency_job_id":"570fd235-fe4a-4a78-a3ae-5bd48d1fd8ed","html_url":"https://github.com/pqnelson/ml","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pqnelson%2Fml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pqnelson%2Fml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pqnelson%2Fml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pqnelson%2Fml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pqnelson","download_url":"https://codeload.github.com/pqnelson/ml/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253604466,"owners_count":21934865,"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":["abstract-machine","acsl","c","compiler","correctness","functional-programming-language","hoare-logic","interpreter","language","parser","twelf"],"created_at":"2024-08-03T18:01:53.063Z","updated_at":"2025-05-11T17:30:53.211Z","avatar_url":"https://github.com/pqnelson.png","language":"C","readme":"This is an exploration of various ways to implement an ML/Haskell-like\nfunctional programming language. From scratch. In C. With an emphasis on\nproving correctness of the implementation.\n\nA generic functional programming language can be decomposed into several\nlevels based on abstraction:\n\n- High level: this is what you program in, when you learn\n  Haskell/OCaml/Standard ML\n- Intermediate level: this is a reduced version of the programming\n  language, types are filled in, some optimizations are made, and so on.\n  It's still human readable at this point.\n- Low Level: This is where the code is compiled into something\n  resembling either assembly language or (binary) bytecode, specifically\n  designed to run on a sort of virtual machine historically called\n  an \"abstract machine\".\n\nThe compilation pipeline looks like:\n\n``` haskell\nML.compile :: [ML.Expr] -\u003e [CoreML.Expr]\nCoreML.compile :: (AbstractMachine a) =\u003e [CoreML.Expr] -\u003e [ByteCode a]\n\ncompile :: (AbstractMachine a) =\u003e [ML.Expr] -\u003e [ByteCode a]\ncompile = CoreML.compile . ML.compile -- compile ML to bytecode\n\neval :: (AbstractMachine a, [ByteCode a]) -\u003e (AbstractMachine a, [ByteCode a])\n```\n\nThe low level abstract machine is the bit worth studying, where there\nare actual substantive differences. Want a lazy language? It's done in\nthe abstract machine. Want to meddle with the garbage collector? Look in\nthe abstract machine. Native array support? Tinker with the abstract machine.\n\nLacking creativity, I'll generically refer to the \"high level\" language\nas \"ML\" for \"MetaLanguage\", the intermediate level language as\n\"Core-ML\", and the low level abstract machines...well, there are many\npossibilities! This is more a study in functional programming language\nimplementation, so I hope to provide a number of abstract machine\nimplementations. \n\n## ML\n\nWe are trying to implement a _pure_ functional programming language. The\nexact definition and criteria for a functional language to be \"pure\"\nvaries, unfortunately, it seems \"safe\" to say: \"A functional language is\n'pure' if all evaluation strategies (call-by-name, call-by-value,\ncall-by-need) produce 'the same results'.\"\n\n(For more on pure functional languages, see Amr Sabry's \"What is Purely\nFunctional Language?\" _J. Functional Programming_ **8**, no.1 (1993):\n1–22,\n[doi:10.1017/S0956796897002943](https://doi.org/10.1017%2FS0956796897002943).)\n\nGeneric features one should expect:\n- Functions are first class values\n- Static typing via type inference\n- Statically scoped\n- Polymorphic types\n- Type system includes support for Algebraic Data Types\n- Garbage Collections\n\n## Game plan for \"Proving Correctness\"\n\nI'm hoping to use the [ACSL](https://frama-c.com/acsl.html) annotations\nfor \"Hoare-triples in C\". This is how we'll prove correctness.\n\nWe will use Twelf to prove the metatheory of the language is correct.\nThis is inspired from previous work in the field, specifically:\n\n- Robert Harper and Daniel R. Licata,\n  \"Mechanizing Metatheory in a Logical Framework.\"\n  [Eprint](https://web.archive.org/web/20160505171738/http://www.cs.cmu.edu/~rwh/papers/mech/jfp07.pdf)\n\n\"Mechanizing the metatheory\" will prove the specification is correct\nusing Twelf, and ACSL will prove our implementation adheres to the\nspecification. (The skeptical reader may ask, \"Isn't using Twelf to prove\nthe correctness of the specification simply punting the problem? It'd be\nas correct as the Twelf implementation program, which may be buggy...\"\nTrue, but Twelf proofs can be checked \"by hand\", if needed.)\n\n## Repository Layout\n\n- `includes/` - All the header files\n- `src/` - All the C code\n- `target/` - All intermediate files that occur in the compilation\n  process live here.\n- `test/` - Unit tests live here.\n- `test-results/` - XML output from running unit tests reside here.\n- `twelf/` - Holds all the Twelf spec files\n\n## FAQ\n\n### Why are you doing this?\n\nI need a functional programming language whose implementation has been\n\"proven correct\".\n\n### What License are you using?\n\nMIT License for all the code.\n\n","funding_links":[],"categories":["C"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpqnelson%2Fml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpqnelson%2Fml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpqnelson%2Fml/lists"}