I am writing a function that accepts only positive numbers, and I want to ensure that it is used correctly both inside the module and elsewhere.
I wanted to write
#lang typed/racket
(require racket/contract)
(: excited-logarithm (-> Number Number))
(define/contract (excited-logarithm ([x : Number]) : Number)
(-> (>=/c 0) number?)
(displayln "Hold on to your decimals, we're going in!")
(log x))
but Typed Racket doesn't provide its own define/contract
, and vanilla define/contract
doesn't understand Typed Racket's annotations (it throws a syntax error).
Can I work around this somehow? Can I use bare contract
to attach a contract to excited-logarithm
the way define/contract
would?
Moreover, is there a good reason I shouldn't be doing this? Is mixing contracts and types discouraged?
Note: I suppose what I really want here is dependent typing, but that's not available in Racket.