> On Dec 24, 2018, at 4:34 PM, wanderley.guimar...@gmail.com wrote:
> 
> I am trying typed/racket for the first time and I can't figure out how to 
> refine a (Listof (U Positive-Byte False)) to (Listof Positive-Byte).
> 
> For example
> > (filter identity '(1 2 3))
> - : (Listof Positive-Byte)
> '(1 2 3)
> > (filter identity '(1 2 3 #f))
> - : (Listof (U False Positive-Byte))
> '(1 2 3)
> 
> It seems that typed/racket can't understand that `identiy` will filter 
> `False` values.
> 
> What is the proper way to filter this value and make sure that the types 
> won't include `False` branches?

Another way to do it, is to define a `truthy?` predicate, which is an identity 
function, assigned a different type that Typed Racket finds more useful for 
filtering:

#lang typed/racket

(: truthy? : (∀ (a) (-> (U a False) Any : #:+ a)))
(define (truthy? v) v)

However, you still need to use `inst` on `truthy?` when you pass it to filter:

> (filter (inst truthy? Positive-Byte) '(1 2 3 #f))
- : (Listof Positive-Byte)
'(1 2 3)

Alex Knauth


> Thanks,
> Wanderley

-- 
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