The following code produces a contract error; I think TR is making
assumptions that it probably shouldn’t be.

Please could someone investigate.

Thanks,

Tim

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#lang typed/racket/gui
(define f (new frame% [label "Frame"]))
(define sldr
   (new slider%
        [parent f]
        [max-value 0]
        [min-value -1]
        [init-value 0]
        [callback (λ (sldr cntrl-evnt)
                    (displayln (get-v)))]
        [label (format "It's false if negative")]))

(define (get-v) : (Option Index)
  (define v (send sldr get-value))
  (printf "~s ~s ~s~%" v (negative? v) (if (negative? v) #f v))
  (if (negative? v)
      #f
      (cast v Index)))

(send f show #t)
(send sldr set-value -1)
(get-v)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Runtime error is:
----------------------------------------------------------------------
broke its own contract
  promised: Index
  produced: -1
  in: Index
  contract from: cast
  blaming: cast
   (assuming the contract is correct)
  at: unsaved-editor:18.6
----------------------------------------------------------------------

-- 
Tim Brown CEng MBCS <tim.br...@cityc.co.uk>
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
                City Computing Limited · www.cityc.co.uk
      City House · Sutton Park Rd · Sutton · Surrey · SM1 2AE · GB
                T:+44 20 8770 2110 · F:+44 20 8770 2130
────────────────────────────────────────────────────────────────────────
City Computing Limited registered in London No:1767817.
Registered Office: City House, Sutton Park Road, Sutton, Surrey, SM1 2AE
VAT No: GB 918 4680 96

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to