Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make comparison operators polymorphic; Add != operator #62

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ rule token = parse
| "=" { DEFEQ(Range.from_lexbuf lexbuf) }
| ("=" (nssymbol+)) { BINOP_EQ(Range.from_lexbuf lexbuf, Lexing.lexeme lexbuf) }

| "!=" { BINOP_NEQ(Range.from_lexbuf lexbuf, Lexing.lexeme lexbuf) }

| "<-" { REVARROW(Range.from_lexbuf lexbuf) }
| "<<" { LTLT(Range.from_lexbuf lexbuf) }
| "<" { LT_EXACT(Range.from_lexbuf lexbuf) }
Expand Down
3 changes: 2 additions & 1 deletion src/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
%token<Range.t> DEFEQ COMMA ARROW REVARROW BAR UNDERSCORE CONS COLON COERCE
%token<Range.t> GT_SPACES GT_NOSPACE LTLT LT_EXACT
%token<Range.t * string> LOWER DOTLOWER UPPER DOTUPPER TYPARAM ROWPARAM MNDLABEL OPTLABEL
%token<Range.t * string> BINOP_TIMES BINOP_DIVIDES BINOP_PLUS BINOP_MINUS BINOP_AMP BINOP_BAR BINOP_EQ BINOP_LT BINOP_GT
%token<Range.t * string> BINOP_TIMES BINOP_DIVIDES BINOP_PLUS BINOP_MINUS BINOP_AMP BINOP_BAR BINOP_EQ BINOP_NEQ BINOP_LT BINOP_GT
%token<Range.t * int> INT
%token<Range.t * float> FLOAT
%token<Range.t * string> BINARY STRING STRING_BLOCK
Expand Down Expand Up @@ -544,6 +544,7 @@ exprlor:
;
exprcomp:
| e1=exprcons; op=BINOP_EQ; e2=exprcomp { binary e1 op e2 }
| e1=exprcons; op=BINOP_NEQ;e2=exprcomp { binary e1 op e2 }
| e1=exprcons; op=oplt; e2=exprcomp { binary e1 op e2 }
| e1=exprcons; op=opgt; e2=exprcomp { binary e1 op e2 }
| e=exprcons { e }
Expand Down
7 changes: 5 additions & 2 deletions src/primitives.ml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ let eff tydoms tyrcv ty0 =
let pid tyrcv = (dr, PidType(Pid(tyrcv)))

let tylogic : poly_type = [b; b] @-> b
let tycomp : poly_type = [i; i] @-> b
let tycomp : poly_type =
let typaram = fresh_bound () in
[typaram; typaram] @-> b
let tyarith : poly_type = [i; i] @-> i
let tyarith_float : poly_type = [f; f] @-> f

Expand Down Expand Up @@ -374,7 +376,8 @@ let initial_environment =
|> add_operators [
("&&", tylogic, "and");
("||", tylogic, "or" );
("==", tycomp , "==" );
("==", tycomp , "=:=" );
("!=", tycomp , "=/=" );
("<=", tycomp , "=<" );
(">=", tycomp , ">=" );
("<" , tycomp , "<" );
Expand Down