Unboxed Vector - Haskell

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Bolt

Is it possible to obtain a Functor instance for unboxed vectors in haskell?

Gabriel Lebec

I am not sure, but aren't all Data.Vector implementations (including .Unboxed) mappable via Data.Vector.Generic (map)? http://hackage.haskell.org/package/vector-0.12.0.3/docs/Data-Vector-Generic.html#v:map I realize this isn't the same thing as being an instance of Functor(in terms of interop with functor-based code) but maybe it is still helpful. (EDIT: also specifically found in http://hackage.haskell.org/package/vector-0.12.0.3/docs/Data-Vector-Unboxed.html#v:map)

Gabriel Lebec

There are also other issues to consider, such as the fact that boxed vectors are instances of Functor while storable and unboxed vectors are not.

From https://www.schoolofhaskell.com/user/commercial/content/vector. I think the best you have with unboxed is the included map. Not sure how/why you can have a working map but not an instance of Functor, strange.

EDIT: I see, b/c the unboxed map type is map :: (Unbox a, Unbox b) => (a -> b) -> Vector a -> Vector b. This means that you can only map between as and bs which satisfy the Unbox constraint. Which isn't general enough for Functor. Makes sense!

Bolt

Yeah I guess one could write something like that!