0

I'm starting to learn Haskell, but I'm finding it hard to figure out the small, little things that the tutorials jumps over. Right now I'm working with tuples in the form of Vector.Fixed:

import qualified Data.Vector.Fixed as VF
import qualified Data.Vector.Fixed.Unboxed (Vec 2)
import qualified Data.Vector.Unboxed as VU

let a = VF.mk2 7 7 :: (Int, Int)
let b = VF.mk2 7 7 :: (Vec2 Int)
  1. What's difference between a and b?

  2. How can I make a VF vector f equivalent of [a, a] = [(7,7), (7,7)]?

  3. How can I make a VU vector g equivalent of [[a], [a,a]] = [[(7,7)], [(7,7), (7,7)]]?

For question 2 and 3, I can't get past the type errors when trying to use the convert function.

  1. I know that my tuples always will be of length 2, but I need a list (or whatever) f of tuples that can be fixed size, and another g that is two-dimensional (e.g. [[(1,2),(3,4)],[(1,2)]] where neither the top list nor the sub lists can be of fixed size. Should I stick to the same type for f and g?

  2. Data.Vector.Fixed and Data.Vector.Unboxed both seem to come from the same package, but they have different maintainers. Are they both official, so to speak, or do they not share any similarities other than that they both are vector implementations?

tsorn
  • 3,365
  • 1
  • 29
  • 48
  • what's the goal, why not use simple pairs `(,)` how should `f` and `g` types interact? At one point you say that `g` is list of `f`s but then you want `f` to be fixed sized but `g` and its sublists to not be fixed. – jakubdaniel May 07 '16 at 12:35
  • `f` can be fixed, but does not have to be. I did not mean that `g` is a list of `f`s; rather, it is a list of sub lists with the same elements as `f` (but likely a in different order). `f` is passed to a function that returns, for each element, the index of the sub list in `g` where the element should be put. I guess I can use simple pairs instead of Vector.Fixed. Is the difference between them that pairs are fixed sized linked lists, while V.Fixed is unlinked? – tsorn May 07 '16 at 13:03
  • I'd say pair is more like a `struct`. – jakubdaniel May 07 '16 at 13:08
  • How are pairs different from V.Fixed? Specifically, the tuples with only contain Ints, will always contain 2 values. – tsorn May 07 '16 at 13:12
  • 2
    `Data.Vector.Unboxed` is from the `vector` package, which is one of the most important packages in the usual haskell ecosystem (total downloads 199903). vectors in the sense of `vector` can be any length, so that e.g. ordinary `Prelude` like functions like `take` and `drop` are supported. `fixed-vector` (total downloads 5281) attempts to use some of the framework from `vector` to make a general library for vectors of fixed length. – Michael May 07 '16 at 16:27

0 Answers0