Skip to content

Commit

Permalink
Remove the function keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Evans committed Oct 8, 2024
1 parent 5c2046c commit 033970f
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 61 deletions.
2 changes: 0 additions & 2 deletions bootstrap/src/hmc/Grammar.hmh
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ include hocc
token EXTERNAL "external" of token_simple
token FALSE "false" of token_simple prec pConstant
token FN "fn" of token_simple prec pLet
token FUNCTION "function" of token_simple prec pLet
token IF "if" of token_simple prec pIf
token IMPORT "import" of token_simple prec pImport
token INCLUDE "include" of token_simple
Expand Down Expand Up @@ -585,7 +584,6 @@ include hocc
| "if" Expr "then" Expr "else" Expr prec pIf
# | Expr ";" Expr
# | "match" Expr "with" PatternMatch
# | "function" PatternMatch
# | "fn" Params "->" Expr # XXX Add effects syntax to arrow.
# | "fn" Params ":" TypeExpr "->" Expr # XXX Add effects syntax to arrow.
-> Xxx
Expand Down
12 changes: 3 additions & 9 deletions bootstrap/src/hmc/scan.ml
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ module Token = struct
| Tok_external of {source: Source.Slice.t}
| Tok_false of {source: Source.Slice.t}
| Tok_fn of {source: Source.Slice.t}
| Tok_function of {source: Source.Slice.t}
| Tok_if of {source: Source.Slice.t}
| Tok_import of {source: Source.Slice.t}
| Tok_include of {source: Source.Slice.t}
Expand Down Expand Up @@ -419,8 +418,6 @@ module Token = struct
formatter |> Fmt.fmt "Tok_false {source=" |> Source.Slice.pp source |> Fmt.fmt "}"
| Tok_fn {source} ->
formatter |> Fmt.fmt "Tok_fn {source=" |> Source.Slice.pp source |> Fmt.fmt "}"
| Tok_function {source} ->
formatter |> Fmt.fmt "Tok_function {source=" |> Source.Slice.pp source |> Fmt.fmt "}"
| Tok_if {source} ->
formatter |> Fmt.fmt "Tok_if {source=" |> Source.Slice.pp source |> Fmt.fmt "}"
| Tok_import {source} ->
Expand Down Expand Up @@ -1069,7 +1066,6 @@ module Token = struct
| Tok_external {source}
| Tok_false {source}
| Tok_fn {source}
| Tok_function {source}
| Tok_if {source}
| Tok_import {source}
| Tok_include {source}
Expand Down Expand Up @@ -1202,10 +1198,9 @@ module Token = struct
let malformations = function
(* Keywords. *)
| Tok_and _ | Tok_also _ | Tok_as _ | Tok_conceal _ | Tok_effect _ | Tok_else _ | Tok_expose _
| Tok_external _ | Tok_false _ | Tok_fn _ | Tok_function _ | Tok_if _ | Tok_import _
| Tok_include _ | Tok_lazy _ | Tok_let _ | Tok_match _ | Tok_mutability _ | Tok_of _
| Tok_open _ | Tok_or _ | Tok_rec _ | Tok_then _ | Tok_true _ | Tok_type _ | Tok_when _
| Tok_with _
| Tok_external _ | Tok_false _ | Tok_fn _ | Tok_if _ | Tok_import _ | Tok_include _ | Tok_lazy _
| Tok_let _ | Tok_match _ | Tok_mutability _ | Tok_of _ | Tok_open _ | Tok_or _ | Tok_rec _
| Tok_then _ | Tok_true _ | Tok_type _ | Tok_when _ | Tok_with _
(* Operators. *)
| Tok_tilde_op _ | Tok_qmark_op _ | Tok_star_star_op _ | Tok_star_op _ | Tok_slash_op _
| Tok_pct_op _ | Tok_plus_op _ | Tok_minus_op _ | Tok_at_op _ | Tok_caret_op _ | Tok_dollar_op _
Expand Down Expand Up @@ -4581,7 +4576,6 @@ module Dfa = struct
| "external" -> Token.Tok_external {source}
| "false" -> Token.Tok_false {source}
| "fn" -> Token.Tok_fn {source}
| "function" -> Token.Tok_function {source}
| "if" -> Token.Tok_if {source}
| "import" -> Token.Tok_import {source}
| "include" -> Token.Tok_include {source}
Expand Down
1 change: 0 additions & 1 deletion bootstrap/src/hmc/scan.mli
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ module Token : sig
| Tok_external of {source: Source.Slice.t}
| Tok_false of {source: Source.Slice.t}
| Tok_fn of {source: Source.Slice.t}
| Tok_function of {source: Source.Slice.t}
| Tok_if of {source: Source.Slice.t}
| Tok_import of {source: Source.Slice.t}
| Tok_include of {source: Source.Slice.t}
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/src/mlc/scan.ml
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,6 @@ let rec next t =
| Tok_external {source} -> Tok_external {source}
| Tok_false {source} -> Tok_false {source}
| Tok_fn {source} -> Tok_uident {source; uident=Constant "fn"}
| Tok_function {source} -> Tok_function {source}
| Tok_if {source} -> Tok_if {source}
| Tok_import {source} -> Tok_import {source}
| Tok_include {source} -> Tok_include {source}
Expand Down Expand Up @@ -753,6 +752,7 @@ let rec next t =
| "begin" -> Tok_begin {source}
| "end" -> Tok_end {source}
| "fun" -> Tok_fun {source}
| "function" -> Tok_function {source}
| "in" -> Tok_in {source}
| "mod" -> Tok_mod {source}
| "module" -> Tok_module {source}
Expand Down
60 changes: 30 additions & 30 deletions doc/design/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,42 +160,42 @@ Pattern construction:

Expressions:

| Operator | Associativity |
| :---------------------------------------------------: | :-----------: |
| `.` ||
| Function/variant application, `lazy` | left |
| `-` (prefix), `~`..., `?`..., `!` ||
| `'` (prefix), `^` (prefix), `>` (prefix) ||
| `**`... | right |
| `*`..., `/`..., `%`... | left |
| `+`..., `-`... | left |
| `::`, `:`... | right |
| `@`..., `^`... | right |
| `=`..., `<`..., `>`..., `\|`..., `$`..., `.`... | left |
| `and` | right |
| `or` | right |
| `,` ||
| `:=` | right |
| `if` ||
| `;` | right |
| `..` ||
| `import` ||
| `open` ||
| `let`, `match`, `fn`, `function`, `expose`, `conceal` ||
| Operator | Associativity |
| :---------------------------------------------: | :-----------: |
| `.` ||
| Function/variant application, `lazy` | left |
| `-` (prefix), `~`..., `?`..., `!` ||
| `'` (prefix), `^` (prefix), `>` (prefix) ||
| `**`... | right |
| `*`..., `/`..., `%`... | left |
| `+`..., `-`... | left |
| `::`, `:`... | right |
| `@`..., `^`... | right |
| `=`..., `<`..., `>`..., `\|`..., `$`..., `.`... | left |
| `and` | right |
| `or` | right |
| `,` ||
| `:=` | right |
| `if` ||
| `;` | right |
| `..` ||
| `import` ||
| `open` ||
| `let`, `match`, `fn`, `expose`, `conceal` ||

### Keyword

The following words are keywords which are used as syntactic elements, and cannot be used for other
purposes.

| Keywords | | | | |
| :--------- | :------- | :----------- | :-------- | :------- |
| `and` | `also` | `as` | `conceal` | `effect`
| `else` | `expose` | `external` | `false` | `fn`
| `function` | `if` | `import` | `include` | `lazy`
| `let` | `match` | `mutability` | `of` | `open`
| `or` | `rec` | `then` | `true` | `type`
| `when` | `with`
| Keywords | | | | |
| :------- | :----------- | :----------- | :-------- | :------- |
| `and` | `also` | `as` | `conceal` | `effect`
| `else` | `expose` | `external` | `false` | `fn`
| `if` | `import` | `include` | `lazy` | `let`
| `match` | `mutability` | `of` | `open` | `or`
| `rec` | `then` | `true` | `type` | `when`
| `with`

### Identifier

Expand Down
8 changes: 4 additions & 4 deletions doc/design/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ Tree = {
empty = Empty
is_empty = function
is_empty t = match t with
| Empty -> true
| Node _ -> false
Expand All @@ -427,11 +427,11 @@ Tree = {
leaf value =
node empty value empty
lchild = function
lchild t = match t with
| Empty -> empty
| Node {lchild; value=_; rchild=_} -> lchild
root_value_opt = function
root_value_opt t = match t with
| Empty -> None
| Node {lchild=_; value; rchild=_} -> Some value
Expand All @@ -442,7 +442,7 @@ Tree = {
root_value = root_value_hlt
rchild = function
rchild t = match t with
| Empty -> empty
| Node {lchild=_; value=_; rchild} -> rchild
}
Expand Down
26 changes: 13 additions & 13 deletions src/Basis/Bool.hm
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ open Rudiments0
T = {
type t: t = bool

to_uns = function
to_uns t = match t with
| false -> 0
| true -> 1

hash_fold t state =
state
|> Uns.hash_fold (to_uns t)
state
|> Uns.hash_fold (to_uns t)

cmp t0 t1 =
let open Cmp
match t0, t1 with
| false, true -> Lt
| false, false
| true, true -> Eq
| true, false -> Gt

of_string = function
let open Cmp
match t0, t1 with
| false, true -> Lt
| false, false
| true, true -> Eq
| true, false -> Gt

of_string s = match s with
| "false" -> false
| "true" -> true
| _ -> not_reached ()

to_string = function
to_string t = match t with
| false -> "false"
| true -> "true"

Expand All @@ -40,7 +40,7 @@ T = {
include T
include Identifiable.Make(T)

of_uns = function
of_uns u = match u with
| 0 -> false
| _ -> true

Expand Down
2 changes: 1 addition & 1 deletion src/Basis/Radix.hm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pp t formatter =
| Dec -> "Dec"
| Hex -> "Hex"

to_uns = function
to_uns t = match t with
| Bin -> 2
| Oct -> 8
| Dec -> 10
Expand Down

0 comments on commit 033970f

Please sign in to comment.