Search code examples
schemerackettyped-racket

Type Checker: Declaration for `n' provided, but `n' has no definition in: n


i am trying to do factorial calculator function in Lisp/drRacket but i got problems and cant figure out.

enter image description here

#lang typed/racket
(: n Number)
(define (faktoriyel n)
    (cond
        ((< n 0) (error "eksi sayıların faktoriyeli olmaz"))
        ((and (>= n 0) (<= n 1)) 1)
        (else (* n (faktoriyel (- n 1))))))


Solution

  • You should be declaring the type of the function, not the variable n:

    (: faktoriyel (-> Number Number))
    

    (-> Number Number) means a function that takes a Number as a parameter and returns a Number.

    See Function Types in the documentation.