# Get to type (apply in-parallel lst)

**URL:** <https://racket.discourse.group/t/get-to-type-apply-in-parallel-lst/683>\
**Category:** Questions & Answers\
**Tags:** typed-racket\
**Created:** [February 11, 2022, 11:01pm UTC](https://racket.discourse.group/t/get-to-type-apply-in-parallel-lst/683 "2022-02-11T23:01:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![scolobb](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/scolobb/32/108_2.png) [@scolobb](https://racket.discourse.group/u/scolobb)\
**Post date:** [February 11, 2022, 11:01pm UTC](https://racket.discourse.group/t/get-to-type-apply-in-parallel-lst/683/1 "2022-02-11T23:01:59Z")

</div>

Hi,

I am trying to type the following function:

```scheme
(: lists-transpose (All (a) (-> (Listof (Listof a)) (Listof (Listof a)))))
(define (lists-transpose lsts)
  (sequence->list (in-values-sequence (apply in-parallel lst))))

```

This tells me:

```scheme
; /home/scolobb/Candies/prj/racket/dds/utils.rkt:456:20: Type Checker: Polymorphic function `in-values-sequence' could not be applied to arguments:
; Argument 1:
; Expected: (Sequenceof a ... a)
; Given: SequenceTop
; 
; in: (in-values-sequence (apply in-parallel lsts))

```

Indeed:

```scheme
> (define lst : (Listof (Listof Symbol)) '((a b) (c d)))
> (apply in-parallel lst)
- : SequenceTop
#<sequence>

```

And `cast`ing doesn't work:

```scheme
> (cast (apply in-parallel lst) (Sequenceof (Listof Symbol)))
; broke its own contract
; any-wrap/c: Unable to protect opaque value passed as `Any`
; value: #<sequence>
; in: Any
; contract from: typed-world
; blaming: typed-world
; (assuming the contract is correct)
; at: utils.rkt/typed::3821-3880
; Context:
; /gnu/store/nivzasmjdp2pgh93hj7wvwrlmwkasljh-racket-minimal-8.3/share/racket/collects/racket/repl.rkt:11:26

```

How do I handle `SequenceTop`?

How do I type `lists-transpose` ?

-  
Sergiu

---

<div class="post-metadata">

**Author:** ![Kalimehtar](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/kalimehtar/32/394_2.png) [@Kalimehtar](https://racket.discourse.group/u/Kalimehtar)\
**Post date:** [February 13, 2022, 12:52pm UTC](https://racket.discourse.group/t/get-to-type-apply-in-parallel-lst/683/2 "2022-02-13T12:52:22Z")

</div>

> How do I type `lists-transpose` ?

```scheme
(: lists-transpose (All (a ...) (-> (List (Listof a) ... a) (Listof (List a ... a)))))
(define (lists-transpose lsts)
  (sequence->list (in-values-sequence (apply in-parallel lsts))))

```

---

<div class="post-metadata">

**Author:** ![scolobb](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/scolobb/32/108_2.png) [@scolobb](https://racket.discourse.group/u/scolobb)\
**Post date:** [February 13, 2022, 5:47pm UTC](https://racket.discourse.group/t/get-to-type-apply-in-parallel-lst/683/3 "2022-02-13T17:47:11Z")

</div>

Wow, thank you very much @Kalimehtar ! I was re-reading the doc of the type of `->` this morning, but I didn't see how I could make it work.

In fact, I thought that `...` could only be used between the arguments of the function, and your solution shows that `...` is much more powerful than I thought. Awesome! 🎉

---

<div class="post-metadata">

**Author:** ![Kalimehtar](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/kalimehtar/32/394_2.png) [@Kalimehtar](https://racket.discourse.group/u/Kalimehtar)\
**Post date:** [February 13, 2022, 5:57pm UTC](https://racket.discourse.group/t/get-to-type-apply-in-parallel-lst/683/4 "2022-02-13T17:57:07Z")

</div>

I simply write `in-parallel` in REPL and got:

```scheme
> in-parallel
- : (All (a ...) (-> (Sequenceof a) ... a (Sequenceof a ... a)))
#<procedure:in-parallel>

```

Then I thought, that Type Checker cannot take finite list of types `(a ...)` when in `(apply in-parallel lst)` `lst` has `(Listof ...)` type. I tried with `(List ..)`: it works. Then I build correct type like given type of `in-parallel`.

---

<div class="post-metadata">

**Author:** ![joskoot](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/joskoot/32/1964_2.png) [@joskoot](https://racket.discourse.group/u/joskoot)\
**Post date:** [February 13, 2022, 10:42pm UTC](https://racket.discourse.group/t/get-to-type-apply-in-parallel-lst/683/5 "2022-02-13T22:42:39Z")

</div>

(define transpose (lambda (x) (map list x)))

(transpose '((a b c) (2 3 4)))

---

<div class="post-metadata">

**Author:** ![scolobb](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/scolobb/32/108_2.png) [@scolobb](https://racket.discourse.group/u/scolobb)\
**Post date:** [February 18, 2022, 2:53pm UTC](https://racket.discourse.group/t/get-to-type-apply-in-parallel-lst/683/6 "2022-02-18T14:53:04Z")

</div>

Thank you @joskoot for your suggestion. Your literal code yields `'(((a b c)) ((2 3 4)))`.

Perhaps you meant something like:

```scheme
(define lists-transpose ((curry map) list))

```

This version would work like this: `(transpose '(a b c) '(2 3 4))`.

The following version will work on a list of lists:

```scheme
(define (lists-transpose lsts) (apply ((curry map) list) lsts))

```

However, when I try to type this code, I run into other type errors related to `curry`, which I am not willing to look at right now 🙂

Thanks anyway: I completely missed the natural approach to transposition by mapping `list` over multiple lists at the same time!
