How to insert unpacked vectors?

This may be a fairly simple question, but I searched around and I can not find the answer.

I would like to present a 2D list using unboxed Vectors. This is easy to do with normal vectors:

> import qualified Data.Vector as V
> V.fromList [V.fromList [1..5]]
[[1,2,3,4,5]]

But if I try to use unpacked vectors:

> import qualified Data.Vector.Unboxed as U
> U.fromList [U.fromList [1..5]]

I get the following error:

• Non type-variable argument
    in the constraint: U.Unbox (U.Vector a)
  (Use FlexibleContexts to permit this)When checking the inferred type
    it :: forall a.
          (U.Unbox (U.Vector a), U.Unbox a, Num a, Enum a) =>
          U.Vector (U.Vector a)

I suspect this has something to do with this:

> V.fromList [1..5]
[1,2,3,4,5]

then

> U.fromList [1..5]
[1.0,2.0,3.0,4.0,5.0]

But I can’t figure out how to avoid this.

Thanks in advance!

+4
source share
1 answer

So, we can start with the sentence given by the compiler:

> :set -XFlexibleContexts

However:

> U.fromList [U.fromList [1..5]]

<interactive>:10:1: error:No instance for (U.Unbox (U.Vector a0))
        arising from a use ofprint

, ( ). , , . . , ,

U.fromList [U.fromList [1..5], U.fromList [1..7]]

C "" , (= ).

+5

Source: https://habr.com/ru/post/1677593/


All Articles