Re: [racket-users] Typed Racket: Using (Sequenceof a) in place of (Listof a)

2017-03-21 Thread WarGrey Gyoudmon Ju
For input arguments, it's okay, (Sequenceof a) does accept (Listof a);
but for the return value, (Listof a) does not accept (Sequenceof a).

You can pass a list as the input, but you cannot narrow the type annotation
in you example,
say (list->vector) satisfies the annotation, both the input and output are
sequences, but the output is not a list.


Nonetheless, you can try the intersection type:

(: step (All (a b)
 (-> (-> a (∩ (Sequenceof a) b) (∩ (Sequenceof a) b))
 a
 (∩ (Sequenceof a) b)
 (∩ (Sequenceof a) b
(define (step fn x seq)
  (fn x seq))


On Tue, Mar 21, 2017 at 12:46 PM, Sourav Datta 
wrote:

> Hello all!
>
> I have a question regarding how sequence abstraction works in TR. In the
> sequence part of the docs it says that a sequence can consist of lists or
> vectors among other things. But does this make a function which ideally
> accepts a (Listof a) to accept something that is declared as a (Sequenceof
> a)? For example, in TR this works:
>
> (: x (Sequenceof Symbol))
> (define x '(a b c d))
>
> However, this shows a type mismatch:
>
> #lang typed/racket
>
> (: step (All (a)
>  (-> (-> a (Sequenceof a) (Sequenceof a))
>  a
>  (Sequenceof a)
>  (Sequenceof a
> (define (step fn x seq)
>   (fn x seq))
>
>
> (step (ann cons (-> Symbol (Listof Symbol) (Listof Symbol)))
>   'a
>   '(b c))
>
> Results in:
>
> Type Checker: Polymorphic function `step' could not be applied to
> arguments:
> Argument 1:
>   Expected: (-> a (Sequenceof a) (Sequenceof a))
>   Given:(-> Symbol (Listof Symbol) (Listof Symbol))
> Argument 2:
>   Expected: a
>   Given:'a
> Argument 3:
>   Expected: (Sequenceof a)
>   Given:(List 'b 'c)
>
> I think, trying to instantiate the polymorphic step function might help
> but I was not able to figure out how.
>
> Thanks in advance.
>
> --
> 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.
>

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


[racket-users] Typed Racket: Using (Sequenceof a) in place of (Listof a)

2017-03-20 Thread Sourav Datta
Hello all!

I have a question regarding how sequence abstraction works in TR. In the 
sequence part of the docs it says that a sequence can consist of lists or 
vectors among other things. But does this make a function which ideally accepts 
a (Listof a) to accept something that is declared as a (Sequenceof a)? For 
example, in TR this works:

(: x (Sequenceof Symbol))
(define x '(a b c d))

However, this shows a type mismatch:

#lang typed/racket

(: step (All (a)
 (-> (-> a (Sequenceof a) (Sequenceof a))
 a
 (Sequenceof a)
 (Sequenceof a
(define (step fn x seq)
  (fn x seq))


(step (ann cons (-> Symbol (Listof Symbol) (Listof Symbol)))
  'a
  '(b c))

Results in:

Type Checker: Polymorphic function `step' could not be applied to arguments:
Argument 1:
  Expected: (-> a (Sequenceof a) (Sequenceof a))
  Given:(-> Symbol (Listof Symbol) (Listof Symbol))
Argument 2:
  Expected: a
  Given:'a
Argument 3:
  Expected: (Sequenceof a)
  Given:(List 'b 'c)

I think, trying to instantiate the polymorphic step function might help but I 
was not able to figure out how.

Thanks in advance.

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