Я попытался создать функцию sqrt+
, которая получит список чисел и вернет список чисел. Может ли кто-нибудь сказать мне, что не так с функцией?create sqrt function in racket
#lang pl 03
(: sqrt+ : (Listof Number) -> (Listof Number))
;; a version of `sqrt' that takes a list of numbers, and return a list
;; with twice the elements, holding the two roots of each of the inputs;
;; throws an error if any input is negative.
(define (sqrt+ ns)
(cond [(null? ns) 0]
[(< (first ns) 0) (error 'ns "`sqrt' requires a nonnegative input ~s")]
[else ((sqrt ns) (* (sqrt ns) -1))]))
Type Checker: type mismatch
expected: (Listof Number)
given: Zero
in: 0
Type Checker: type mismatch
expected: Nonnegative-Real
given: (Pairof Nonnegative-Real (Listof Number))
in: ns
Type Checker: type mismatch
expected: Nonnegative-Real
given: (Pairof Nonnegative-Real (Listof Number))
in: ns
Type Checker: Summary: 3 errors encountered
in:
0
ns
ns
Подсказка: Ошибка в вашем еще пункте, где вы называете 'sqrt' на' (ListOf Number) '. – Majora320