Skip to content

Commit ba13f5c

Browse files
authored
Fix input-output signatures (#999)
Since 0.101.0 we will finally catch more illegal `def` signatures. As the grammar for input/output types is rather restricted, this would error otherwise
1 parent be6411e commit ba13f5c

File tree

10 files changed

+15
-15
lines changed

10 files changed

+15
-15
lines changed

modules/background_task/task.nu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export def spawn [
1919
--after (-a): int # Start the task once all specified tasks have successfully finished. As soon as one of the dependencies fails, this task will fail as well.
2020
--priority (-o): string # Start this task with a higher priority. The higher the number, the faster it will be processed.
2121
--label (-l): string # Label the task. This string will be shown in the `status` column of `task status`.
22-
] -> int {
22+
]: nothing -> int {
2323
mut args = []
2424

2525
if $working_directory != null {

modules/recursion/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use tramp.nu
4343
# This version just returns either the value or a thunk.
4444
# Meant to be used in a trampoline
4545
# But still uses APS
46-
def fact [n: int, acc=1] -> int {
46+
def fact [n: int, acc=1]: nothing -> int {
4747
if $n <= 1 { return $acc } else {
4848
{|| fact ($n - 1) ($n * $acc) } # The thunk being returned to the trampoline
4949
}

modules/recursion/countdown.nu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Simple countdown counter from some number n to 0. Returns 0 at end
33
# Designed to be used with the tramp module to avoid stack overflows via the
44
# use of the Trampoline method.
5-
def countdown [n: int] -> int {
5+
def countdown [n: int]: nothing -> int {
66
if $n == 0 {
77
0
88
} else {

modules/recursion/even-odd.nu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
# Return true if number is even. Calls mutually recursive odd function
1414
# if number is greater than 1.
15-
def even [n: int, acc=true] -> any {
15+
def even [n: int, acc=true]: nothing -> any {
1616
if $n == 0 { return $acc } else if $n == 1 {
1717
return (not $acc) } else {
1818
{|| odd ($n - 2) (not $acc) }
@@ -22,7 +22,7 @@ def even [n: int, acc=true] -> any {
2222

2323
# Returns true if number is odd. Will cooperate with even in a mutually recursive fashion.
2424
# Warning: do not pass any numbers less than 0
25-
def odd [n: int, acc=true] -> bool {
25+
def odd [n: int, acc=true]: nothing -> bool {
2626
if $n == 0 { return (not $acc) } else if $n == 1 {
2727
return $acc } else {
2828
{|| even ($n - 2) (not $acc) }

modules/recursion/fact.nu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This version just returns either the value or a thunk.
33
# Meant to be used in a trampoline
44
# But still uses APS
5-
def fact [n: int, acc=1] -> int {
5+
def fact [n: int, acc=1]: nothing -> int {
66
if $n <= 1 { return $acc } else {
77
{|| fact ($n - 1) ($n * $acc) } # The thunk being returned to the trampoline
88
}

modules/recursion/fib.nu

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# This version is non-tail call optimized and might consume large values
55
# of stack space even for small values of n. It is also not memoized so run time
66
# performance for even quite small values of N is very poor.
7-
def fib-nontail [n: int] -> int {
7+
def fib-nontail [n: int]: nothing -> int {
88
if $n == 0 {
99
0
1010
} else if $n == 1 {
@@ -21,7 +21,7 @@ def fib-nontail [n: int] -> int {
2121

2222
# Returns the Fibonacci number for the index n. Uses the double APS method to
2323
# ensure the recursive call is in thetail position.
24-
def fib-aps [n: int, acc: int=1, accp: int=1] -> int {
24+
def fib-aps [n: int, acc: int=1, accp: int=1]: nothing -> int {
2525
if ($n == 0) or ($n == 1) {
2626
$n
2727
} else if $n == 2 {
@@ -35,7 +35,7 @@ def fib-aps [n: int, acc: int=1, accp: int=1] -> int {
3535

3636
# Return the Fibonacci number for given index n
3737
# This version relies on the trampoline helper
38-
def fib [n: int, acc: int=1, accp: int=1] -> int {
38+
def fib [n: int, acc: int=1, accp: int=1]: nothing -> int {
3939
if ($n == 0) or ($n == 1) {
4040
$n
4141
} else if $n == 2 {

modules/recursion/gcd.nu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Based on this clear explanation from Rutgers: https://sites.math.rutgers.edu/~greenfie/gs2004/euclid.html
33

44
# Returns the GCD of its 2 arguments
5-
def gcd [i1: int, i2: int] -> int {
5+
def gcd [i1: int, i2: int]: nothing -> int {
66
mut a = $i1; mut b = $i2
77
if $a < $b { let tmp = $a; $a = $b; $b = $tmp }
88
let q = $a // $b; let r = $a mod $b

modules/recursion/merge.nu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# merge 2 sorted lists
22

33
# Merge 2 sorted lists
4-
def merge-2 [l: list, r: list] -> list {
4+
def merge-2 [l: list, r: list]: nothing -> list {
55
mut ol = []
66
mut lprime = $l; mut rprime = $r
77
let mx = ($l | length) + ($r | length)
@@ -24,7 +24,7 @@ mut lprime = $l; mut rprime = $r
2424
# Merge sort a list
2525
# This version is non tail call optimized and might blow the stack for
2626
# large lists.
27-
def sort-nontail [x: list] -> list {
27+
def sort-nontail [x: list]: nothing -> list {
2828
let $n = ($x | length)
2929
let n_2: int = $n // 2
3030

modules/recursion/tramp.nu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export def create [thunk: any] {
2626
# The parameter val must be either a terminating value or closure, which will get run until
2727
# the terminating value is returned from the current closure which
2828
# is returned from this function.
29-
export def test [val: any] -> any {
29+
export def test [val: any]: nothing -> any {
3030
let cl = (create $val)
3131
do $cl
3232
}
@@ -43,7 +43,7 @@ export def test [val: any] -> any {
4343

4444
# Explicitly bounces the trampoline over a recursive function without first
4545
# creating a closure .
46-
export def recurse [val: any] -> any {
46+
export def recurse [val: any]: nothing -> any {
4747
mut maybe_thunk = $val
4848
while ($maybe_thunk | describe) == closure {
4949
$maybe_thunk = (do $maybe_thunk)

modules/yadm/mod.nu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
def generate_viable_bash_string_flags [
66
flag_record:record # A object filled all known flags and their values.
7-
] -> list<string> {
7+
]: nothing -> list<string> {
88

99

1010

0 commit comments

Comments
 (0)