From a809ad19757c5cb6b6b651b137701abb7ec4dc18 Mon Sep 17 00:00:00 2001 From: Steve Dunham Date: Sat, 23 Nov 2024 16:23:37 -0800 Subject: [PATCH] remove node dependencies from Prelude.newt --- aoc2023/Day1.newt | 1 + aoc2023/Day2.newt | 2 ++ aoc2023/Node.newt | 7 +++++++ newt-vscode/syntaxes/newt.tmLanguage.json | 2 +- playground/samples/Prelude.newt | 8 ++++---- playground/src/main.ts | 2 +- port/Prelude.newt | 8 ++++---- 7 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 aoc2023/Node.newt diff --git a/aoc2023/Day1.newt b/aoc2023/Day1.newt index 187d753..8ac2e12 100644 --- a/aoc2023/Day1.newt +++ b/aoc2023/Day1.newt @@ -1,6 +1,7 @@ module Day1 import Prelude +import Node digits1 : List Char -> List Int digits1 Nil = Nil diff --git a/aoc2023/Day2.newt b/aoc2023/Day2.newt index f5c7028..7da3e30 100644 --- a/aoc2023/Day2.newt +++ b/aoc2023/Day2.newt @@ -1,6 +1,7 @@ module Day2 import Prelude +import Node Draw : U Draw = Int × Int × Int @@ -84,6 +85,7 @@ part2 (MkGame n parts :: rest) = run : String -> IO Unit run fn = do + putStrLn fn text <- readFile fn case mapM parseGame (split (trim text) "\n") of Left err => putStrLn $ "fail " ++ err diff --git a/aoc2023/Node.newt b/aoc2023/Node.newt new file mode 100644 index 0000000..37a04e8 --- /dev/null +++ b/aoc2023/Node.newt @@ -0,0 +1,7 @@ +module Node + +import Prelude + +pfunc fs : JSObject := "require('fs')" +pfunc getArgs : List String := "arrayToList(String, process.argv)" +pfunc readFile : (fn : String) -> IO String := "(fn) => (w) => MkIORes(Unit, fs.readFileSync(fn, 'utf8'), w)" diff --git a/newt-vscode/syntaxes/newt.tmLanguage.json b/newt-vscode/syntaxes/newt.tmLanguage.json index 2d2c8c0..7a8c8b1 100644 --- a/newt-vscode/syntaxes/newt.tmLanguage.json +++ b/newt-vscode/syntaxes/newt.tmLanguage.json @@ -16,7 +16,7 @@ }, { "name": "keyword.newt", - "match": "\\b(data|where|class|instance|case|of|let|if|then|else|forall|∀|in|U|module|import|ptype|pfunc|infix|infixl|infixr)\\b" + "match": "\\b(data|where|do|class|instance|case|of|let|if|then|else|forall|∀|in|U|module|import|ptype|pfunc|infix|infixl|infixr)\\b" }, { "name": "string.js", diff --git a/playground/samples/Prelude.newt b/playground/samples/Prelude.newt index 14f3009..4a98028 100644 --- a/playground/samples/Prelude.newt +++ b/playground/samples/Prelude.newt @@ -220,7 +220,6 @@ pfunc arrayToList : {a} → Array a → List a := "(a,arr) => { }" -pfunc getArgs : List String := "arrayToList(String, process.argv)" -- for now I'll run this in JS pfunc lines : String → List String := "(s) => arrayToList(s.split('\\n'))" @@ -297,9 +296,6 @@ pfunc unpack : String -> List Char }" -ptype Dummy -pfunc fs : Dummy := "require('fs')" -pfunc readFile : (fn : String) -> IO String := "(fn) => (w) => MkIORes(Unit, fs.readFileSync(fn, 'utf8'), w)" foldl : {A B : U} -> (B -> A -> B) -> B -> List A -> B foldl f acc Nil = acc @@ -329,3 +325,7 @@ instance Ord Int where printLn : {a} {{Show a}} → a → IO Unit printLn a = putStrLn $ show a + +-- opaque JSObject +ptype JSObject + diff --git a/playground/src/main.ts b/playground/src/main.ts index b64961a..76b166e 100644 --- a/playground/src/main.ts +++ b/playground/src/main.ts @@ -192,7 +192,7 @@ const SAMPLES = [ "Lists.newt", "Day1.newt", "Day2.newt", - "Lib.newt", + "Prelude.newt", "TypeClass.newt", "Combinatory.newt", ]; diff --git a/port/Prelude.newt b/port/Prelude.newt index 14f3009..4a98028 100644 --- a/port/Prelude.newt +++ b/port/Prelude.newt @@ -220,7 +220,6 @@ pfunc arrayToList : {a} → Array a → List a := "(a,arr) => { }" -pfunc getArgs : List String := "arrayToList(String, process.argv)" -- for now I'll run this in JS pfunc lines : String → List String := "(s) => arrayToList(s.split('\\n'))" @@ -297,9 +296,6 @@ pfunc unpack : String -> List Char }" -ptype Dummy -pfunc fs : Dummy := "require('fs')" -pfunc readFile : (fn : String) -> IO String := "(fn) => (w) => MkIORes(Unit, fs.readFileSync(fn, 'utf8'), w)" foldl : {A B : U} -> (B -> A -> B) -> B -> List A -> B foldl f acc Nil = acc @@ -329,3 +325,7 @@ instance Ord Int where printLn : {a} {{Show a}} → a → IO Unit printLn a = putStrLn $ show a + +-- opaque JSObject +ptype JSObject +