[racket] Typed racket problem
Well, I should have added that I've found this:
(: process (-> OptList Void))
(define (process ol)
(let ([s (optval 'size ol)])
(if (and s (< (cast s Integer) 0))
(displayln "wrong value")
(displayln "ok")))
)
but I didn't find this really nice. Actually, I was hoping for
something more concise.
--
Manfred
On Sun, 30 Nov 2014 10:13:48 +0100
Manfred Lotz <manfred.lotz at arcor.de> wrote:
> Hi there,
> I've got another problem with typed racket.
>
> Let us say I have an assoc list with options for a program. These
> options could be of type String, Boolean, or Integer.
>
> Now in my program I want to check certain options but I don't know how
> to do without Typed Racket screaming at me.
>
> Here a minimal example:
>
> #lang typed/racket
>
> (define-type Myopt (U String Boolean Integer))
> (define-type OptList (Listof (Pairof Symbol Myopt)))
>
>
> (: olist OptList)
> (define olist (list '(dir . ".")
> '(verbose . #t)
> '(size . 12)))
>
> (: optval (-> Symbol OptList Myopt))
> (define (optval v ol)
> (let ([val (assoc v ol)])
> (if val
> (cdr val)
> (error "Unexpected option encountered"))))
>
> (: process (-> OptList Void))
> (define (process ol)
> (if (< (optval 'size ol) 0)
> (displayln "wrong value")
> (displayln "ok")))
>
>
> I get an error:
> Type Checker: type mismatch
> expected: Real
> given: Myopt
> in: (optval (quote size) ol)
>
>
> How could I solve this?
>
>