Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.
Is it possible to obtain a Functor instance for unboxed vectors in haskell?
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)
Data.Vector
.Unboxed
Data.Vector.Generic (map)
Functor
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.
map
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!
map :: (Unbox a, Unbox b) => (a -> b) -> Vector a -> Vector b
a
b
Unbox
Thanks!
Yeah I guess one could write something like that!
Is it possible to obtain a Functor instance for unboxed vectors in haskell?
I am not sure, but aren't all
Data.Vector
implementations (including.Unboxed
) mappable viaData.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 ofFunctor
(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)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 workingmap
but not an instance ofFunctor
, 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 betweena
s andb
s which satisfy theUnbox
constraint. Which isn't general enough forFunctor
. Makes sense!Thanks!
Yeah I guess one could write something like that!