From ac2c7ac015a84a496e8a5ba6474b319db2d30f04 Mon Sep 17 00:00:00 2001 From: Henry Wandover Date: Thu, 6 Feb 2025 15:08:29 -0500 Subject: [PATCH 1/7] adding scripts --- bld.sh | 5 +++++ ins.sh | 4 ++++ 2 files changed, 9 insertions(+) create mode 100644 bld.sh create mode 100644 ins.sh diff --git a/bld.sh b/bld.sh new file mode 100644 index 000000000..874c838d6 --- /dev/null +++ b/bld.sh @@ -0,0 +1,5 @@ +#!/usr/bin/bash + +dune build +mv _build/default/bin/links.exe links + diff --git a/ins.sh b/ins.sh new file mode 100644 index 000000000..56d875268 --- /dev/null +++ b/ins.sh @@ -0,0 +1,4 @@ +#!/usr/bin/bash + +dune build +sudo mv _build/default/bin/links.exe /usr/local/bin/links From 1765e705655e0d3524777c3710ed6845192db2ae Mon Sep 17 00:00:00 2001 From: Henry Wandover Date: Thu, 6 Feb 2025 16:45:55 -0500 Subject: [PATCH 2/7] Created TODO.md --- TODO.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 TODO.md diff --git a/TODO.md b/TODO.md new file mode 100644 index 000000000..5de8fb50e --- /dev/null +++ b/TODO.md @@ -0,0 +1,3 @@ +# TODO (yung-turabian) + +- [ ] Add some test cases. From d245f32eacceb84240b740c5b69b2b31ab60d3be Mon Sep 17 00:00:00 2001 From: Henry <77937076+yung-turabian@users.noreply.github.com> Date: Thu, 6 Feb 2025 21:40:23 -0500 Subject: [PATCH 3/7] effect is now a reserved keyword in OCaml --- core/irCheck.ml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/irCheck.ml b/core/irCheck.ml index f3f6df4de..52fdc3612 100644 --- a/core/irCheck.ml +++ b/core/irCheck.ml @@ -1053,11 +1053,11 @@ struct (* For each case branch, the corresponding entry goes directly into the field spec map of the inner effect row *) let inner_effects_map_from_branches = StringMap.map (fun x -> Present x) branch_presence_spec_types in (* We now add all entries from the outer effects that were not touched by the handler to the inner effects *) - let inner_effects_map = StringMap.fold (fun effect outer_presence_spec map -> - if StringMap.mem effect inner_effects_map_from_branches then + let inner_effects_map = StringMap.fold (fun effect' outer_presence_spec map -> + if StringMap.mem effect' inner_effects_map_from_branches then map else - StringMap.add effect outer_presence_spec map + StringMap.add effect' outer_presence_spec map ) inner_effects_map_from_branches outer_effects_map in let inner_effects = Row (inner_effects_map, outer_effects_var, outer_effects_dualized) in From 476931e8fef2ce435e007c42682e63f03a9dcb7b Mon Sep 17 00:00:00 2001 From: Henry <77937076+yung-turabian@users.noreply.github.com> Date: Thu, 6 Feb 2025 21:40:58 -0500 Subject: [PATCH 4/7] add build scripts --- bld.sh | 0 ins.sh | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 bld.sh mode change 100644 => 100755 ins.sh diff --git a/bld.sh b/bld.sh old mode 100644 new mode 100755 diff --git a/ins.sh b/ins.sh old mode 100644 new mode 100755 From 7518d31155172461ed6a07922a7f7b3885527268 Mon Sep 17 00:00:00 2001 From: Henry Wandover Date: Fri, 7 Feb 2025 22:52:50 -0500 Subject: [PATCH 5/7] Fixing emacs script --- bld.sh | 0 links-mode.el | 2 ++ prelude.links | 17 +++++++++++++++++ 3 files changed, 19 insertions(+) mode change 100644 => 100755 bld.sh diff --git a/bld.sh b/bld.sh old mode 100644 new mode 100755 diff --git a/links-mode.el b/links-mode.el index fe45518a5..6cc1279e7 100644 --- a/links-mode.el +++ b/links-mode.el @@ -46,6 +46,8 @@ ;; Can be generated with `links --print-keywords`. ;; TODO We should do that automatically as part of the build process somehow. + +;; ./links --print-keywords | awk '{ print "\""$0"\""}' (defconst links-keywords '( "alien" diff --git a/prelude.links b/prelude.links index c210282d8..ffb28c43f 100644 --- a/prelude.links +++ b/prelude.links @@ -1,3 +1,20 @@ + +# Work on natural number type P.O.C. +# I liek this idea though +typename Nat = + [|Succ: Nat + |Zero + |]; + + +# IDK what I'm doing here, simply experimenting with Links undocumented keywords. +# I probably should stick to just implementing in lib.ml for now +infixl 6 `plus`; +sig `plus` : (a::Numeric, a) -> a +op f `plus` g { + f + g +} + fun assert(ok, msg) { if (not(ok)) debug("assertion failed: " ^^ msg) else () } From 1182532da055fc2461ea9ab72975bd1295b22ef2 Mon Sep 17 00:00:00 2001 From: Henry <77937076+yung-turabian@users.noreply.github.com> Date: Sat, 8 Feb 2025 17:54:52 -0500 Subject: [PATCH 6/7] Bits --- TODO.md | 6 +++++- core/lib.ml | 28 +++++++++++++++++--------- links-mode.el | 17 ++++++++++++++-- prelude.links | 3 --- tests/numeric-operations.tests | 36 ++++++++++++++++++++++++++++++++++ 5 files changed, 75 insertions(+), 15 deletions(-) create mode 100644 tests/numeric-operations.tests diff --git a/TODO.md b/TODO.md index 5de8fb50e..2441eb70b 100644 --- a/TODO.md +++ b/TODO.md @@ -1,3 +1,7 @@ # TODO (yung-turabian) -- [ ] Add some test cases. +- [-] Add some test cases. +- [ ] Have type inference convert, for example, int to float in a operation like 2.0 + 2? Hide behind an experimental guard if so. +- [ ] Singleton kinds, they classify type cons by reavling their identity. + - [ ] Higher singletons, S(c :: k) where k is a kind and c is a constructor of kind k. +- [ ] If given the ability to create new subkinds, then just force the creation to derive from one of the three 'base' (Type, Row, Presnece) or even one of their subkinds such as "Base." \ No newline at end of file diff --git a/core/lib.ml b/core/lib.ml index 96dbca191..da390ecda 100644 --- a/core/lib.ml +++ b/core/lib.ml @@ -243,11 +243,11 @@ let project_datetime (f: CalendarShow.t -> int) : located_primitive * Types.data let env : (string * (located_primitive * Types.datatype * pure)) list = [ - "+", numeric_op ( + ) ( +. ) PURE PURE; - "-", numeric_op ( - ) ( -. ) PURE PURE; - "*", numeric_op ( * ) ( *. ) PURE PURE; - "/", numeric_op ( / ) ( /. ) IMPURE PURE; - "^", numeric_op (pow) ( ** ) PURE PURE; + "+", numeric_op ( + ) ( +. ) PURE PURE; + "-", numeric_op ( - ) ( -. ) PURE PURE; + "*", numeric_op ( * ) ( *. ) PURE PURE; + "/", numeric_op ( / ) ( /. ) IMPURE PURE; + "^", numeric_op (pow) ( ** ) PURE PURE; "mod", int_op ( mod ) IMPURE; @@ -260,6 +260,16 @@ let env : (string * (located_primitive * Types.datatype * pure)) list = [ "^^", string_op ( ^ ) PURE; + (* moved abs to make use of ad hoc ability, + ideally there could be a way to bootstrap prelude similar to #786 *) + "abs", + (p1 (fun n -> match n with + | `Int _ -> Value.box_int ( let x = (Value.unbox_int n) in if x > 0 then x else -x ) + | `Float _ -> Value.box_float ( let x = (Value.unbox_float n) in if x > 0.0 then x else -.x ) + | _ -> raise (runtime_type_error ("Cannot computer absolute value: " ^ Value.string_of_value n))), + datatype "(a::Numeric) -> a", + PURE); + "max_int", (Value.box_int max_int, datatype "Int", @@ -750,10 +760,10 @@ let env : (string * (located_primitive * Types.datatype * pure)) list = [ PURE); "negate", - (p1 (fun i -> match i with - | `Int _ -> Value.box_int (- (Value.unbox_int i)) - | `Float _ -> Value.box_float (-. (Value.unbox_float i)) - | _ -> raise (runtime_type_error ("Cannot negate: " ^ Value.string_of_value i))), + (p1 (fun n -> match n with + | `Int _ -> Value.box_int (- (Value.unbox_int n)) + | `Float _ -> Value.box_float (-. (Value.unbox_float n)) + | _ -> raise (runtime_type_error ("Cannot negate: " ^ Value.string_of_value n))), datatype "(a::Numeric) -> a", PURE); diff --git a/links-mode.el b/links-mode.el index fe45518a5..239245641 100644 --- a/links-mode.el +++ b/links-mode.el @@ -45,8 +45,7 @@ st)) ;; Can be generated with `links --print-keywords`. -;; TODO We should do that automatically as part of the build process somehow. -(defconst links-keywords +(defconst links-backup-keywords '( "alien" "as" @@ -121,6 +120,20 @@ "with" )) +;;; Added by yung-turabian 2025 +(defconst links-keywords + ; Not the best test + (if (string-equal + (shell-command-to-string (concat links-executable " --version")) + "Links version 0.9.9 (Burghmuirhead)\n" + ) + (split-string + (shell-command-to-string (concat links-executable " --print-keywords")) + "\n" " ") + links-backup-keywords) + ) + + (defconst links-font-lock-keywords (list ;; comments diff --git a/prelude.links b/prelude.links index c210282d8..7d7fca74d 100644 --- a/prelude.links +++ b/prelude.links @@ -307,9 +307,6 @@ fun dropWhile(pred, list) { # else 0 # } -fun abs(i) { - if (i < 0) -i else i -} sig init : ([a]) ~> [a] fun init(list) { diff --git a/tests/numeric-operations.tests b/tests/numeric-operations.tests new file mode 100644 index 000000000..ee2ae2a5a --- /dev/null +++ b/tests/numeric-operations.tests @@ -0,0 +1,36 @@ +Addition and multiplication [1] +10 + 20 * 30 +stdout : 610 : Int + +Addition and multiplication [2] +20.0 * 30.0 + 10.0 +stdout : 610.0 : Float + +Addition, division, subtraction, and multiplication +100.50 + 200.20 / 10.10 - 3.10 * 10.10 +stdout : 89.0117821782 : Float + +Inproper usage +2 - 3.3 +stderr : @..* +exit : 1 + +Absolute value of integer +abs(-9) +stdout : 9 : Int + +Absolute value of float +abs(-9.54) +stdout : 9.54 : Float + +Prefix notation +{var plus = (+); plus(1.5, (+)(2.5,3.5))} +stdout : 7.5 : Float + +Unary minus +(-1) +stdout : -1 : Int + +Unary float minus +(-1.0) +stdout : -1.0 : Float \ No newline at end of file From e62b243c8b7aef0a67c64ed25a6a6b3a9d2be757 Mon Sep 17 00:00:00 2001 From: Henry <77937076+yung-turabian@users.noreply.github.com> Date: Sat, 8 Feb 2025 17:56:55 -0500 Subject: [PATCH 7/7] unnamed --- prelude.links | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/prelude.links b/prelude.links index 7d44c7e80..7d7fca74d 100644 --- a/prelude.links +++ b/prelude.links @@ -1,20 +1,3 @@ - -# Work on natural number type P.O.C. -# I liek this idea though -typename Nat = - [|Succ: Nat - |Zero - |]; - - -# IDK what I'm doing here, simply experimenting with Links undocumented keywords. -# I probably should stick to just implementing in lib.ml for now -infixl 6 `plus`; -sig `plus` : (a::Numeric, a) -> a -op f `plus` g { - f + g -} - fun assert(ok, msg) { if (not(ok)) debug("assertion failed: " ^^ msg) else () }