{"id":20704611,"url":"https://github.com/egison/typed-egison","last_synced_at":"2025-10-11T07:12:20.459Z","repository":{"id":153025979,"uuid":"126757995","full_name":"egison/typed-egison","owner":"egison","description":null,"archived":false,"fork":false,"pushed_at":"2019-01-29T05:21:54.000Z","size":3022,"stargazers_count":17,"open_issues_count":3,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-07-18T19:16:28.873Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/egison.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,"zenodo":null}},"created_at":"2018-03-26T01:38:56.000Z","updated_at":"2020-07-01T16:09:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"282a9c82-beca-4e82-84f0-d89d506585b5","html_url":"https://github.com/egison/typed-egison","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/egison/typed-egison","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egison%2Ftyped-egison","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egison%2Ftyped-egison/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egison%2Ftyped-egison/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egison%2Ftyped-egison/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/egison","download_url":"https://codeload.github.com/egison/typed-egison/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egison%2Ftyped-egison/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271248325,"owners_count":24726086,"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","status":"online","status_checked_at":"2025-08-19T02:00:09.176Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-17T01:13:07.115Z","updated_at":"2025-10-11T07:12:15.422Z","avatar_url":"https://github.com/egison.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Typed Egison\nThis is a derivation of Egison.  \nThe purpose of this project is to make Egison a statically typed language.  \nThis document is focused on the type system of Egison and written for developers of Egison.  \nYou can test codes started with `\u003e` in the Typed Egison interpreter.\n\n## How to install and Run Interpreter\nI assume you use Linux.\nPlease use following commands to build Typed Egison.\n```\ngit clone https://github.com/egison/typed-egison.git\nstack init\nstack solver\nstack build\n```\nAfter build, you can start repl by\n```\nstack exec egison\n```\n## Commands in the Interpreter\nYou can use these commands in the interpreter\n- `print-type-of` \u0026emsp;\u0026nbsp;show the type of expression\n- `define`\u0026emsp;\u0026emsp;\u0026emsp;\u0026emsp;\u0026emsp;         define fucntions or constants\n- `define-type-of` \u0026nbsp;\u0026nbsp;\u0026nbsp;define type of functions or constants\n- `define-ADT`\u0026emsp;\u0026emsp;\u0026ensp;\u0026nbsp;\u0026nbsp;     define new ADT\n\n## Built-in Types\nThe built-in types of Egison are\n`Char`, `String`, `Bool`, `Integer`, `Tuple`, `Collection`, `Fun`, `Pattern` and `Matcher`.\n\n### Char, String, Bool, Integer\nYou can check the type of a expression using `print-type-of`.  \n```\n\u003e (print-type-of c#a)\nc#a :: Char\n\n\u003e (print-type-of \"Hello\")\n\"Hello\" :: String\n\n\u003e (print-type-of #t)\n#t :: Bool\n\n\u003e (print-type-of 42)\n42 :: Integer\n```\n### Tuple\nTuple is a set of some types.\n```\n\u003e (print-type-of [10 \"hoge\"])\n[10 \"hoge\"] :: (Tuple Integer String)\n```\n\n### Collection\nCollection is used to represent a data which contains many same type datum.\n```\n\u003e (print-type-of {10 20 40})\n{10 20 40} :: (Collection Integer)\n```\n\n## Fun\nFun is an abbreviation of a function of course.\nFunctions in Egison are take a tuple and return a value.\n```\n\u003e (print-type-of (lambda [$x] (b.+ x 10)))\n(lambda [$x] (b.+ x 10)) :: (Fun (Tuple Integer) Integer)\n```\nThis means `(lambda [$x] (b.+ x 10))` takes a tuple of integer and return integer.\n\n### Pattern, Matcher\nThese two types are deeply related to `match-all` syntax.\nIn short, `match-all` looks like following.\n```\n(match-all \"Data\" \"How to match\" [\"Pattern\" \"Result\"])\n\"Collection of Result\"\n```\n\nThe following is an example of pattern matching in Egison.\n```\n\u003e (match-all \u003cPair 2 5\u003e (unorderd-pair integer) [\u003cpair ,5 $x\u003e x])\n{2}\n```\nYou don't have to understand details of `\u003cPair 2 5\u003e`, `(unorderd-pair integer)` and `\u003cpair ,5 $x\u003e`.\nWhat I want to teach in this section is types of these parts. These types are\n```\n\u003cPair 2 5\u003e :: PairII\n(unordered-pair integer) :: Matcher PairII\n\u003cpair ,5 $x\u003e :: Pattern PairII\n```\n`PairII` is user-defined ADT. I will explain about ADT in a later section.\n\nIn this example, `match-all` takes 3 arguments.  \nTheir types are `PairII`, `(Matcher PairII)`, `(Tuple (Pattern PairII) Integer)` respectively and return `(Collection Integer)`.   \nMore generally, `match-all` takes 3 arguments, `a`, `(Matcher a)`, `(Tuple (Pattern a) b)` and return `(Collection b)`.  \n `a` and `b` are variables which refer some types like `Integer`, `Bool` or `PairII`.\n\nIn rough words, `match-all` has this type\n```\n(Fun (Tuple a (Matcher a) (Tuple (Pattern a) b)) (Collection b))\n```\n\n## Algebraic Data Type\nAs you can see in the previous section, you can define algebraic data type in Egison.\n`define-ADT` is a syntax for defining ADT.\n```\n(define-ADT \"Name of type\" \u003c\"Name of type constructor\" \"type1\" \"type2\" ...\u003e \u003c\"Name of type constructor\" ...\u003e)\n```\n\nThe name of type and names of type constructors must start from a capital case.  \nFor example, `PairII` is defined using following code.\n```\n(define-ADT PairII \u003cPair Integer Integer\u003e)\n```\nAfter you execute above command, data constructor `Pair` and pattern constructor `pair` will be defined.   \nNames of pattern constructors are same with data constructors but pattern constructors are begun with small cases.\n```\n\u003e (print-type-of Pair)\nPair :: (Fun (Tuple Integer Integer) PairII\n\u003e (print-type-of pair)\npair :: (Fun (Tuple (Pattern Integer) (Pattern Integer)) (Pattern PairII))\n```\nPlease be careful. Pattern constructor has defined ***automatically***.   \nWhen you define ADT, you must be careful not to conflict names.   \nYou can use `print-type-of` to check whether a name is used or not.\n```\n\u003e (print-type-of unusedname)\nCannot decide the type of unusedname\n```\n## Advanced Topics\n### Type declaration for built-in functions\nBuilt-in functions (ex. `b.+`, `eq?`) are defined in Egison interpreter.  \nSo the type checker cannot infer the type of these functions.  \nWe must give the type declaration of these functions to type checker.  \nFor such purpose, we can use `define-type-of`.  \nWhen you write\n```\n(define-type-of $b.+ (Fun (Tnple Integer Integer) Integer))\n```\ntype checker believe `b.+` has `(Fun (Tnple Integer Integer) Integer)` type.  \nFor more examples, please check `lib/core/type-primitive.egi`.  \nType checker loads this file when it starts.  \n\n***Caution***  \nWhen you use ADT or type variables in `define-type-of`, you must write like `(TypeVar Pair)`.\nFor examples,\n```\n(define-type-of $eq? (Fun (Tuple (TypeVar a) (TypeVar a)) Bool))\n(define-type-of somevalue (TypeVar PairII))\n```\n\n### Theoretical Base of Type System of Typed Egison\nTheoretically, the type system of Egison is an extension of simply typed lambda calculus.  \nI extended simply typed lambda calculus with let polymorphism, Collection, Pattern, Matcher.\n\n### Implicit Conversion\nI made implicit conversion for Egison.  \nBut it was not used now in the master branch.  \nYou can check the implementation in hs-src/Language/Egison/ImplConv.hs.  \nSyntax for implicit conversion are `absolute-implicit-conversion` and `implicit-conversion`.  \n`absolute-implicit-conversion` convert all possible variables absolutely.  \nThis means that when you define absolute implicit conversion from String to Integer,  \nall values typed String is converted to Integer absolutely.  \n`implicit-conversion` convert all possible variables so that the type check success.  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fegison%2Ftyped-egison","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fegison%2Ftyped-egison","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fegison%2Ftyped-egison/lists"}