From 2af901f0cfc48b6a8270ec940c2e21dbfbf3972f Mon Sep 17 00:00:00 2001 From: Natapat Samutpong Date: Sat, 9 Apr 2022 21:04:08 +0700 Subject: [PATCH] fix parser type --- crates/parser/src/lib.rs | 4 ++-- example/iter.hz | 20 ++++++++++---------- example/tuples.hz | 14 -------------- 3 files changed, 12 insertions(+), 26 deletions(-) delete mode 100644 example/tuples.hz diff --git a/crates/parser/src/lib.rs b/crates/parser/src/lib.rs index ba09b65..ccbea32 100644 --- a/crates/parser/src/lib.rs +++ b/crates/parser/src/lib.rs @@ -31,7 +31,7 @@ fn typehint_parser() -> impl Parser, Error = Simple impl Parser, Error = Simple int) (current: int): void = do if current == @len(vec) then do end else do - -- iter logic - -- TODO: function as argument - @get(vec, current) |> @write(_) + @get(vec, current) + |> fn(_) + |> @write(_) @write("\n") - iter_(vec, current + 1) + iter_(vec, fn, current + 1) end end end -fun iter (vec: vec_int): void = do - iter_(vec, 0) -end +fun iter (vec: [int]) (fn: |int| -> int): void = iter_(vec, fn, 0) + +fun mul10 (x: int): int = x * 10 fun main: void = do - let foo: vec_int = [69, 420, 727, 1337, 42069, 69420] - iter(foo) + let foo: [int] = [69, 420, 727, 1337, 42069, 69420] + iter(foo, mul10) end \ No newline at end of file diff --git a/example/tuples.hz b/example/tuples.hz deleted file mode 100644 index 016f342..0000000 --- a/example/tuples.hz +++ /dev/null @@ -1,14 +0,0 @@ -fun mul (foo: int) (bar: int) : int = foo * bar -fun map - (fn: |int, int| -> int) - (to: int) - : int -= fn(to, 10) - -fun main: void = do - let foo : int = 69 - let bar : int = 10 - - map(mul, foo) - |> @write(_) -end