Skip to content

Commit e9a4f1e

Browse files
committed
Add fixity declarations
1 parent b374e28 commit e9a4f1e

4 files changed

Lines changed: 55 additions & 2 deletions

File tree

lexer.mll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ rule token = parse
270270
| "fun" { FUN }
271271
| "if" { IF }
272272
| "in" { IN }
273+
| "fixity" { FIXITY }
273274
| "..." { ELLIPSIS }
274275
| "let" { LET }
275276
| "||" { LOGICAL_OR }

parser.mly

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ let parse_error s = raise (Source.Error (Source.nowhere_region, s))
3939
%token IMPORT
4040
%token WRAP_OP UNWRAP_OP
4141
%token ROLL_OP UNROLL_OP
42+
%token FIXITY
4243

4344
%token EOF
4445

@@ -109,13 +110,27 @@ head :
109110
{ $1 }
110111
;
111112

112-
names :
113+
syms :
114+
| sym
115+
{ [$1] }
116+
| syms sym
117+
{ $2::$1 }
118+
;
119+
120+
plainnames :
113121
| name
114122
{ [$1] }
115-
| name names
123+
| name plainnames
116124
{ $1::$2 }
117125
;
118126

127+
names :
128+
| FIXITY syms
129+
{ List.map (fun n -> ("fixity." ^ n.it) @@ n.at) $2 }
130+
| plainnames
131+
{ $1 }
132+
;
133+
119134
label :
120135
| name
121136
{ $1 }

prelude/index.1ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import "./primitives"
22

3+
Succ = {
4+
type t _ = {}
5+
}
6+
37
Bool = {
48
...Bool
59
not b = if b then false else true

prelude/index.1mls

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
11
local import "./primitives"
22

3+
Succ: {
4+
type t _
5+
}
6+
7+
Prec: {
8+
type _0 n = n
9+
type _1 n = Succ.t (_0 n)
10+
type _2 n = Succ.t (_1 n)
11+
type _3 n = Succ.t (_2 n)
12+
type _4 n = Succ.t (_3 n)
13+
type _5 n = Succ.t (_4 n)
14+
type _6 n = Succ.t (_5 n)
15+
type _7 n = Succ.t (_6 n)
16+
type _8 n = Succ.t (_7 n)
17+
}
18+
19+
Assoc: {
20+
type L n = (Succ.t n, n)
21+
type N n = ( n, n)
22+
type R n = ( n, Succ.t n)
23+
}
24+
25+
type Fixity (type prec _) (type assoc _) = {prec, assoc}
26+
27+
fixity * / % = Fixity Prec.8 Assoc.L
28+
fixity + - = Fixity Prec.7 Assoc.L
29+
fixity :: ++ = Fixity Prec.6 Assoc.R
30+
fixity < <= <> == > >= = Fixity Prec.5 Assoc.N
31+
fixity << >> = Fixity Prec.4 Assoc.L
32+
fixity |> = Fixity Prec.3 Assoc.L
33+
fixity <| = Fixity Prec.3 Assoc.R
34+
335
Alt: {
436
type t _ _
537
inl 'a 'b: a -> t a b
@@ -93,6 +125,7 @@ type char = Char.t
93125
type int = Int.t
94126
type list a = List.t a
95127
type opt a = Opt.t a
128+
type succ = Succ.t
96129
type text = Text.t
97130
type zero = Zero.t
98131

0 commit comments

Comments
 (0)