<div dir="ltr">Indeed, it worked (thanks again!):<br><br>{-# Language ScopedTypeVariables #-}<br>module Main where<br><br>import Control.Monad.Primitive<br>import qualified Data.Vector.Unboxed<br>import qualified Data.Vector.Generic as VG<br>import qualified Data.Vector.Unboxed.Mutable as VM<br>import qualified Data.Vector.Unboxed as V<br><br>main :: IO ()<br>main = do<br>  v :: VM.MVector RealWorld Int <- VM.new 1<br>  VM.write v 0 (3 :: Int)<br>  x <- VM.read v 0<br>  v' <- V.freeze v<br>  print $ VG.head v'<br>  print $ VM.length v<br><br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Aug 5, 2017 at 10:54 PM, Cody Goodman <span dir="ltr"><<a href="mailto:codygman.consulting@gmail.com" target="_blank">codygman.consulting@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto">Thanks! I'll try it out in a bit.</div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Aug 5, 2017 10:32 PM, "Amos Robinson" <<a href="mailto:amos.robinson@gmail.com" target="_blank">amos.robinson@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Yes, I believe Data.Vector.Generic.freeze will work. But I would use the one from Data.Vector.Unboxed unless you really need the generic version. Sometimes the extra constraints in the generic version can be a bit cumbersome, requiring extra type annotations where the specific versions don't.</div><br><div class="gmail_quote"><div dir="ltr">On Sun, 6 Aug 2017 at 13:22 Cody Goodman <<a href="mailto:codygman.consulting@gmail.com" target="_blank">codygman.consulting@gmail.com</a><wbr>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I'm not back at a computer yet, but so I and others reading these archives in the future know: Does that mean that freeze from Data.Vector.Generic.freeze should work for me then?<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Aug 5, 2017 at 10:05 PM, Amos Robinson <span dir="ltr"><<a href="mailto:amos.robinson@gmail.com" target="_blank">amos.robinson@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Mutable is the type family from Vector to MVector. So the result type will be an instance of Vector, but the input MVector doesn't need to be.<div>It's a little confusing that freeze is in Data.Unboxed.Vector, not .Mutable: <a href="https://hackage.haskell.org/package/vector-0.12.0.1/docs/Data-Vector-Unboxed.html#v:freeze" target="_blank">https://hackage.hask<wbr>ell.org/package/vector-0.12.0.<wbr>1/docs/Data-Vector-Unboxed.<wbr>html#v:freeze</a></div></div><div class="m_2593501790525215183m_3421976462564006862m_-2238733016284271094HOEnZb"><div class="m_2593501790525215183m_3421976462564006862m_-2238733016284271094h5"><br><div class="gmail_quote"><div dir="ltr">On Sun, 6 Aug 2017 at 12:59 Cody Goodman <<a href="mailto:codygman.consulting@gmail.com" target="_blank">codygman.consulting@gmail.com</a><wbr>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I see the type is:<br><br><p class="m_2593501790525215183m_3421976462564006862m_-2238733016284271094m_-3914177534819969092m_8983470806532160153gmail-src"><a id="m_2593501790525215183m_3421976462564006862m_-2238733016284271094m_-3914177534819969092m_8983470806532160153gmail-v:freeze" class="m_2593501790525215183m_3421976462564006862m_-2238733016284271094m_-3914177534819969092m_8983470806532160153gmail-def">freeze</a> :: (<a href="https://hackage.haskell.org/package/primitive-0.6.2.0/docs/Control-Monad-Primitive.html#t:PrimMonad" target="_blank">PrimMonad</a> m, <a href="https://hackage.haskell.org/package/vector-0.12.0.1/docs/Data-Vector-Generic.html#t:Vector" target="_blank">Vector</a> v a) => <a href="https://hackage.haskell.org/package/vector-0.12.0.1/docs/Data-Vector-Generic.html#t:Mutable" target="_blank">Mutable</a> v (<a href="https://hackage.haskell.org/package/primitive-0.6.2.0/docs/Control-Monad-Primitive.html#t:PrimState" target="_blank">PrimState</a> m) a -> m (v a)</p><p class="m_2593501790525215183m_3421976462564006862m_-2238733016284271094m_-3914177534819969092m_8983470806532160153gmail-src"><br></p><p class="m_2593501790525215183m_3421976462564006862m_-2238733016284271094m_-3914177534819969092m_8983470806532160153gmail-src">So there is a Vector constrant that MVector will not have. Does the Mutable type family get around this somehow?</p><p class="m_2593501790525215183m_3421976462564006862m_-2238733016284271094m_-3914177534819969092m_8983470806532160153gmail-src"><br></p><p class="m_2593501790525215183m_3421976462564006862m_-2238733016284271094m_-3914177534819969092m_8983470806532160153gmail-src">There doesn't seem to be a freeze function specifically for <a href="http://Data.Vector.Unboxed.Mutable.MV">Data.Vector.Unboxed.Mutable.MV</a><wbr>ector listed at: <a href="https://hackage.haskell.org/package/vector-0.12.0.1/docs/Data-Vector-Unboxed-Mutable.html" target="_blank">https://hackage.haskell.org/pa<wbr>ckage/vector-0.12.0.1/docs/Dat<wbr>a-Vector-Unboxed-Mutable.html</a></p><p class="m_2593501790525215183m_3421976462564006862m_-2238733016284271094m_-3914177534819969092m_8983470806532160153gmail-src">Thanks,</p><p class="m_2593501790525215183m_3421976462564006862m_-2238733016284271094m_-3914177534819969092m_8983470806532160153gmail-src">Cody<br></p></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Aug 5, 2017 at 9:56 PM, Amos Robinson <span dir="ltr"><<a href="mailto:amos.robinson@gmail.com" target="_blank">amos.robinson@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I think you want "Data.Vector.Generic.freeze", or unsafeFreeze if you are sure you won't modify the mutable vector after making it immutable.<div><a href="https://hackage.haskell.org/package/vector-0.12.0.1/docs/Data-Vector-Generic.html#v:freeze" target="_blank">https://hackage.haskell.org/pa<wbr>ckage/vector-0.12.0.1/docs/Dat<wbr>a-Vector-Generic.html#v:freeze</a><br></div></div><br><div class="gmail_quote"><div><div class="m_2593501790525215183m_3421976462564006862m_-2238733016284271094m_-3914177534819969092m_8983470806532160153h5"><div dir="ltr">On Sun, 6 Aug 2017 at 12:46 Cody Goodman <<a href="mailto:codygman.consulting@gmail.com" target="_blank">codygman.consulting@gmail.com</a><wbr>> wrote:<br></div></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_2593501790525215183m_3421976462564006862m_-2238733016284271094m_-3914177534819969092m_8983470806532160153h5"><div dir="ltr"><div><div><div>I want to do this so I can use the Data.Vector.Unboxed.Generic functions requiring the Vector constraint, namely the maxIndex function. Implementing maxIndex for <a href="http://Data.Vector.Unboxed.Mutable.MV">Data.Vector.Unboxed.Mutable.MV</a><wbr>ector would be useful as well, but I'm even more confused at how to do that or where to begin.<br></div><div><br>Here is some stubbed out code demonstrating this.<br><br>{-# Language ScopedTypeVariables #-}<br>module Main where<br><br>import Control.Monad.Primitive<br>import qualified Data.Vector.Unboxed<br>import qualified Data.Vector.Generic as VG<br>import qualified Data.Vector.Unboxed.Mutable as VM<br>import qualified Data.Vector.Unboxed as V<br><br>toImmutable :: VM.MVector RealWorld Int -> V.Vector Int<br>toImmutable = undefined<br><br>main :: IO ()<br>main = do<br>  v :: VM.MVector RealWorld Int <- VM.new 1<br>  VM.write v 0 (3 :: Int)<br>  x <- VM.read v 0<br>  -- y <- VG.head . toImmutable $ v<br>  -- print y<br>  print $ VM.length v<br><br>{-<br></div><div>Thanks,<br><br><br></div><div>Cody<br>-}<br></div></div></div></div></div></div><span>
______________________________<wbr>_________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bi<wbr>n/mailman/listinfo/haskell-caf<wbr>e</a><br>
Only members subscribed via the mailman list are allowed to post.</span></blockquote></div>
</blockquote></div><br></div>
</blockquote></div>
</div></div></blockquote></div><br></div>
</blockquote></div>
</blockquote></div></div>
</div></div></blockquote></div><br></div>