
Hello, What is the best way to take: [1, 2, 3, 4 ] And convert it to: [ [ [ 1 ], [ 2 ] ], [ [3]. [4] ] ] so that each member pair is: [ [1], [2] ] roughly analogous to a 1x2 vector? Thanks in advance and thank you for your time.

Il 27 febbraio 2021 alle 18:07 A. Mc. ha scritto:
Hello,
What is the best way to take: [1, 2, 3, 4 ]
And convert it to:
[ [ [ 1 ], [ 2 ] ], [ [3]. [4] ] ]
so that each member pair is:
[ [1], [2] ]
roughly analogous to a 1x2 vector?
A 1×2 vector would be
[[1 2], [3, 4]]
am I wrong? If so, a quick and dirty solution could be d2 :: [a] -> [[a]] d2 [] = [] d2 [a] = error "odd element" d2 as = let (is, es) = splitAt 2 as in is : d2 es -- λ> d2 [1..6] -- [[1,2],[3,4],[5,6]]

If you are okay with a library, you can use the split library for this. stack exec --package split -- ghci
chunksOf 2 [1,2,3,4,5,6] [[1,2],[3,4],[5,6]]
On Sat, Feb 27, 2021 at 9:08 PM A. Mc. <47dragonfyre@gmail.com> wrote:
Hello,
What is the best way to take: [1, 2, 3, 4 ]
And convert it to:
[ [ [ 1 ], [ 2 ] ], [ [3]. [4] ] ]
so that each member pair is:
[ [1], [2] ]
roughly analogous to a 1x2 vector?
Thanks in advance and thank you for your time. _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
participants (3)
-
A. Mc.
-
David McBride
-
Francesco Ariis