Haskell: From Vectors to Unboxed Vectors2019 Community Moderator ElectionConcatenating two std::vectorsHow to find out if an item is present in a std::vector?How do I erase an element from std::vector<> by index?Getting started with HaskellWhy is Java Vector (and Stack) class considered obsolete or deprecated?What is Haskell actually useful for?What is the easiest way to initialize a std::vector with hardcoded elements?Appending a vector to a vectorLarge-scale design in Haskell?Haskell: Lists, Arrays, Vectors, Sequences

I got the following comment from a reputed math journal. What does it mean?

How do hiring committees for research positions view getting "scooped"?

How can I wire 7 outdoor posts correctly?

What is the significance behind "40 days" that often appears in the Bible?

Does multi-classing into Fighter give you heavy armor proficiency?

Violin - Can double stops be played when the strings are not next to each other?

Recruiter wants very extensive technical details about all of my previous work

I seem to dance, I am not a dancer. Who am I?

Fewest number of steps to reach 200 using special calculator

Writing in a Christian voice

Why is there so much iron?

What exactly term 'companion plants' means?

How to generate binary array whose elements with values 1 are randomly drawn

PTIJ What is the inyan of the Konami code in Uncle Moishy's song?

Could Sinn Fein swing any Brexit vote in Parliament?

Maths symbols and unicode-math input inside siunitx commands

What does Deadpool mean by "left the house in that shirt"?

Do US professors/group leaders only get a salary, but no group budget?

Do native speakers use "ultima" and "proxima" frequently in spoken English?

Turning a hard to access nut?

Knife as defense against stray dogs

Bash - pair each line of file

Help rendering a complicated sum/product formula

What does "Four-F." mean?



Haskell: From Vectors to Unboxed Vectors



2019 Community Moderator ElectionConcatenating two std::vectorsHow to find out if an item is present in a std::vector?How do I erase an element from std::vector<> by index?Getting started with HaskellWhy is Java Vector (and Stack) class considered obsolete or deprecated?What is Haskell actually useful for?What is the easiest way to initialize a std::vector with hardcoded elements?Appending a vector to a vectorLarge-scale design in Haskell?Haskell: Lists, Arrays, Vectors, Sequences










0















Today I was working in transforming some code that used Data.Vector to a more "memory efficient" Data.Vector.Unboxed when I suddenly realized a missing instance.



If I do this in ghci:



import qualified Data.Vector as V
V.singleton V.empty :: V.Vector (V.Vector Int)
[[]]


That is correct, Vector was printed correctly. However, if I try the same with Vector.Unboxed:



import qualified Data.Vector.Unboxed as VU
:set -XFlexibleContexts
VU.singleton VU.empty :: VU.Vector (VU.Vector Int)


I get the error:



<interactive>:10:1: error:
• No instance for (VU.Unbox (VU.Vector Int))
arising from a use of ‘VU.singleton’
• In the expression:
VU.singleton VU.empty :: VU.Vector (VU.Vector Int)
In an equation for ‘it’:
it = VU.singleton VU.empty :: VU.Vector (VU.Vector Int)


Which drives me to the question, how do I correctly implement an unboxed vector of vectors?





Side note:



The objective I was trying to reach was a generic splitChunks function, with the basic premise of splitting a vector into sub vectors of fixed size, a very primitive implementation using common vectors was as follows:



-- With an arbitrary vector and a positive integer of known size it will create a vector that has splitted the original into sections. Example:
-- vec = [1,2,3,4,5,6,7,8,9,10]
-- size = 4
-- result = [[1,2,3,4],[5,6,7,8],[9,10]]
splitChunks :: V.Vector p -> Int -> V.Vector (V.Vector p)
splitChunks vec size
| size <= 0 = V.empty
| otherwise = fst $ until condition opr (V.empty, vec)
where condition = V.null . snd
opr (x, y) = let (l, r) = V.splitAt size y in (V.snoc x l, r)


Then, when I tried to move from Vector to Vector.Unboxed, I got the same problem as described before.










share|improve this question
























  • You can't! Unboxed values have to be fixed size

    – Benjamin Hodgson
    Mar 6 at 21:54











  • I updated the post making it explicit the desired type I would like to have, in this case Vector (Vector Int). That would mean, Int is unboxed and the size is known.

    – Invoke
    Mar 6 at 21:59






  • 2





    So the outer vector will be a boxed vector. V.Vector (VU.Vector Int)

    – Benjamin Hodgson
    Mar 6 at 22:00











  • While the size of Int is known, the size of VU.Vector Int is not because the number of Int elements in the vector is dynamic. You could have a static length vector. You could use the vector from fixed-vector for fixed size unboxed vectors.

    – Thomas M. DuBuisson
    Mar 6 at 22:26











  • I will check the library fixed-vector and see if that fits to the action I am trying to perform.

    – Invoke
    Mar 7 at 0:49















0















Today I was working in transforming some code that used Data.Vector to a more "memory efficient" Data.Vector.Unboxed when I suddenly realized a missing instance.



If I do this in ghci:



import qualified Data.Vector as V
V.singleton V.empty :: V.Vector (V.Vector Int)
[[]]


That is correct, Vector was printed correctly. However, if I try the same with Vector.Unboxed:



import qualified Data.Vector.Unboxed as VU
:set -XFlexibleContexts
VU.singleton VU.empty :: VU.Vector (VU.Vector Int)


I get the error:



<interactive>:10:1: error:
• No instance for (VU.Unbox (VU.Vector Int))
arising from a use of ‘VU.singleton’
• In the expression:
VU.singleton VU.empty :: VU.Vector (VU.Vector Int)
In an equation for ‘it’:
it = VU.singleton VU.empty :: VU.Vector (VU.Vector Int)


Which drives me to the question, how do I correctly implement an unboxed vector of vectors?





Side note:



The objective I was trying to reach was a generic splitChunks function, with the basic premise of splitting a vector into sub vectors of fixed size, a very primitive implementation using common vectors was as follows:



-- With an arbitrary vector and a positive integer of known size it will create a vector that has splitted the original into sections. Example:
-- vec = [1,2,3,4,5,6,7,8,9,10]
-- size = 4
-- result = [[1,2,3,4],[5,6,7,8],[9,10]]
splitChunks :: V.Vector p -> Int -> V.Vector (V.Vector p)
splitChunks vec size
| size <= 0 = V.empty
| otherwise = fst $ until condition opr (V.empty, vec)
where condition = V.null . snd
opr (x, y) = let (l, r) = V.splitAt size y in (V.snoc x l, r)


Then, when I tried to move from Vector to Vector.Unboxed, I got the same problem as described before.










share|improve this question
























  • You can't! Unboxed values have to be fixed size

    – Benjamin Hodgson
    Mar 6 at 21:54











  • I updated the post making it explicit the desired type I would like to have, in this case Vector (Vector Int). That would mean, Int is unboxed and the size is known.

    – Invoke
    Mar 6 at 21:59






  • 2





    So the outer vector will be a boxed vector. V.Vector (VU.Vector Int)

    – Benjamin Hodgson
    Mar 6 at 22:00











  • While the size of Int is known, the size of VU.Vector Int is not because the number of Int elements in the vector is dynamic. You could have a static length vector. You could use the vector from fixed-vector for fixed size unboxed vectors.

    – Thomas M. DuBuisson
    Mar 6 at 22:26











  • I will check the library fixed-vector and see if that fits to the action I am trying to perform.

    – Invoke
    Mar 7 at 0:49













0












0








0








Today I was working in transforming some code that used Data.Vector to a more "memory efficient" Data.Vector.Unboxed when I suddenly realized a missing instance.



If I do this in ghci:



import qualified Data.Vector as V
V.singleton V.empty :: V.Vector (V.Vector Int)
[[]]


That is correct, Vector was printed correctly. However, if I try the same with Vector.Unboxed:



import qualified Data.Vector.Unboxed as VU
:set -XFlexibleContexts
VU.singleton VU.empty :: VU.Vector (VU.Vector Int)


I get the error:



<interactive>:10:1: error:
• No instance for (VU.Unbox (VU.Vector Int))
arising from a use of ‘VU.singleton’
• In the expression:
VU.singleton VU.empty :: VU.Vector (VU.Vector Int)
In an equation for ‘it’:
it = VU.singleton VU.empty :: VU.Vector (VU.Vector Int)


Which drives me to the question, how do I correctly implement an unboxed vector of vectors?





Side note:



The objective I was trying to reach was a generic splitChunks function, with the basic premise of splitting a vector into sub vectors of fixed size, a very primitive implementation using common vectors was as follows:



-- With an arbitrary vector and a positive integer of known size it will create a vector that has splitted the original into sections. Example:
-- vec = [1,2,3,4,5,6,7,8,9,10]
-- size = 4
-- result = [[1,2,3,4],[5,6,7,8],[9,10]]
splitChunks :: V.Vector p -> Int -> V.Vector (V.Vector p)
splitChunks vec size
| size <= 0 = V.empty
| otherwise = fst $ until condition opr (V.empty, vec)
where condition = V.null . snd
opr (x, y) = let (l, r) = V.splitAt size y in (V.snoc x l, r)


Then, when I tried to move from Vector to Vector.Unboxed, I got the same problem as described before.










share|improve this question
















Today I was working in transforming some code that used Data.Vector to a more "memory efficient" Data.Vector.Unboxed when I suddenly realized a missing instance.



If I do this in ghci:



import qualified Data.Vector as V
V.singleton V.empty :: V.Vector (V.Vector Int)
[[]]


That is correct, Vector was printed correctly. However, if I try the same with Vector.Unboxed:



import qualified Data.Vector.Unboxed as VU
:set -XFlexibleContexts
VU.singleton VU.empty :: VU.Vector (VU.Vector Int)


I get the error:



<interactive>:10:1: error:
• No instance for (VU.Unbox (VU.Vector Int))
arising from a use of ‘VU.singleton’
• In the expression:
VU.singleton VU.empty :: VU.Vector (VU.Vector Int)
In an equation for ‘it’:
it = VU.singleton VU.empty :: VU.Vector (VU.Vector Int)


Which drives me to the question, how do I correctly implement an unboxed vector of vectors?





Side note:



The objective I was trying to reach was a generic splitChunks function, with the basic premise of splitting a vector into sub vectors of fixed size, a very primitive implementation using common vectors was as follows:



-- With an arbitrary vector and a positive integer of known size it will create a vector that has splitted the original into sections. Example:
-- vec = [1,2,3,4,5,6,7,8,9,10]
-- size = 4
-- result = [[1,2,3,4],[5,6,7,8],[9,10]]
splitChunks :: V.Vector p -> Int -> V.Vector (V.Vector p)
splitChunks vec size
| size <= 0 = V.empty
| otherwise = fst $ until condition opr (V.empty, vec)
where condition = V.null . snd
opr (x, y) = let (l, r) = V.splitAt size y in (V.snoc x l, r)


Then, when I tried to move from Vector to Vector.Unboxed, I got the same problem as described before.







haskell vector






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 0:59







Invoke

















asked Mar 6 at 21:48









InvokeInvoke

11310




11310












  • You can't! Unboxed values have to be fixed size

    – Benjamin Hodgson
    Mar 6 at 21:54











  • I updated the post making it explicit the desired type I would like to have, in this case Vector (Vector Int). That would mean, Int is unboxed and the size is known.

    – Invoke
    Mar 6 at 21:59






  • 2





    So the outer vector will be a boxed vector. V.Vector (VU.Vector Int)

    – Benjamin Hodgson
    Mar 6 at 22:00











  • While the size of Int is known, the size of VU.Vector Int is not because the number of Int elements in the vector is dynamic. You could have a static length vector. You could use the vector from fixed-vector for fixed size unboxed vectors.

    – Thomas M. DuBuisson
    Mar 6 at 22:26











  • I will check the library fixed-vector and see if that fits to the action I am trying to perform.

    – Invoke
    Mar 7 at 0:49

















  • You can't! Unboxed values have to be fixed size

    – Benjamin Hodgson
    Mar 6 at 21:54











  • I updated the post making it explicit the desired type I would like to have, in this case Vector (Vector Int). That would mean, Int is unboxed and the size is known.

    – Invoke
    Mar 6 at 21:59






  • 2





    So the outer vector will be a boxed vector. V.Vector (VU.Vector Int)

    – Benjamin Hodgson
    Mar 6 at 22:00











  • While the size of Int is known, the size of VU.Vector Int is not because the number of Int elements in the vector is dynamic. You could have a static length vector. You could use the vector from fixed-vector for fixed size unboxed vectors.

    – Thomas M. DuBuisson
    Mar 6 at 22:26











  • I will check the library fixed-vector and see if that fits to the action I am trying to perform.

    – Invoke
    Mar 7 at 0:49
















You can't! Unboxed values have to be fixed size

– Benjamin Hodgson
Mar 6 at 21:54





You can't! Unboxed values have to be fixed size

– Benjamin Hodgson
Mar 6 at 21:54













I updated the post making it explicit the desired type I would like to have, in this case Vector (Vector Int). That would mean, Int is unboxed and the size is known.

– Invoke
Mar 6 at 21:59





I updated the post making it explicit the desired type I would like to have, in this case Vector (Vector Int). That would mean, Int is unboxed and the size is known.

– Invoke
Mar 6 at 21:59




2




2





So the outer vector will be a boxed vector. V.Vector (VU.Vector Int)

– Benjamin Hodgson
Mar 6 at 22:00





So the outer vector will be a boxed vector. V.Vector (VU.Vector Int)

– Benjamin Hodgson
Mar 6 at 22:00













While the size of Int is known, the size of VU.Vector Int is not because the number of Int elements in the vector is dynamic. You could have a static length vector. You could use the vector from fixed-vector for fixed size unboxed vectors.

– Thomas M. DuBuisson
Mar 6 at 22:26





While the size of Int is known, the size of VU.Vector Int is not because the number of Int elements in the vector is dynamic. You could have a static length vector. You could use the vector from fixed-vector for fixed size unboxed vectors.

– Thomas M. DuBuisson
Mar 6 at 22:26













I will check the library fixed-vector and see if that fits to the action I am trying to perform.

– Invoke
Mar 7 at 0:49





I will check the library fixed-vector and see if that fits to the action I am trying to perform.

– Invoke
Mar 7 at 0:49












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55032707%2fhaskell-from-vectors-to-unboxed-vectors%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55032707%2fhaskell-from-vectors-to-unboxed-vectors%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

Алба-Юлія

Захаров Федір Захарович