Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I specify a void function in typed racket?

What should be the type annotation of foo?

(define (foo)
  (println "hello"))

I tried these but none of them worked:

(: foo (-> () ()))
(: foo (-> Void Void))
like image 343
JRR Avatar asked Oct 23 '25 16:10

JRR


1 Answers

The type (-> Void Void) is for a function that takes in a void, and returns a void. Your foo function, takes in no arguments, and returns a void. As such, the type you want for it is actually:

(: foo (-> Void))
(define (foo)
  (println "hello"))

As a side note:

If you wanted to modify foo to have the type (-> Void Void), you could do this:

(define (foo _)
  (print "Don't do this though"))

As for:

(: foo (-> () ()))

That is syntactically invalid.

like image 84
Leif Andersen Avatar answered Oct 25 '25 10:10

Leif Andersen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!