You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#!/usr/bin/env cabal
{- cabal:build-depends: , base , vector ^>= 0.13-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
moduleMainwhereimportqualifiedData.Vector.GenericasGimportqualifiedData.Vector.Generic.MutableasMimportqualifiedData.Vector.PrimitiveasPimportqualifiedData.Vector.UnboxedasUnewtypeFoo=FooIntderivingP.PrimnewtypeinstanceU.MVectorsFoo=MV_Int (P.MVectorsFoo)
newtypeinstanceU.VectorFoo=V_Int (P.VectorFoo)
derivingvia (U.UnboxViaPrimFoo) instanceM.MVectorMVectorFooderivingvia (U.UnboxViaPrimFoo) instanceG.VectorVectorFooinstanceUnboxFoomain::IO()
main =doputStrLn"OK"pure()
I get following error with GHC 9.4
$ cabal run Test.hs
/tmp/test/Test.hs:24:54: error:
Not in scope: type constructor or class ‘MVector’
Suggested fix:
Perhaps use one of these:
‘M.MVector’ (imported from Data.Vector.Generic.Mutable),
‘U.MVector’ (imported from Data.Vector.Unboxed),
‘P.MVector’ (imported from Data.Vector.Primitive)
|
24 | deriving via (U.UnboxViaPrim Foo) instance M.MVector MVector Foo
| ^^^^^^^
/tmp/test/Test.hs:25:54: error:
Not in scope: type constructor or class ‘Vector’
Suggested fix:
Perhaps use one of these:
‘G.Vector’ (imported from Data.Vector.Generic),
‘U.Vector’ (imported from Data.Vector.Unboxed),
‘P.Vector’ (imported from Data.Vector.Primitive)
|
25 | deriving via (U.UnboxViaPrim Foo) instance G.Vector Vector Foo
| ^^^^^^
/tmp/test/Test.hs:26:10: error:
Not in scope: type constructor or class ‘Unbox’
Suggested fix:
Perhaps use ‘U.Unbox’ (imported from Data.Vector.Unboxed)
|
26 | instance Unbox Foo
| ^^^^^
After fixing qualified imports I try again with
#!/usr/bin/env cabal
{- cabal:build-depends: , base , vector ^>= 0.13-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
moduleMainwhereimportqualifiedData.Vector.GenericasGimportqualifiedData.Vector.Generic.MutableasMimportqualifiedData.Vector.PrimitiveasPimportqualifiedData.Vector.UnboxedasUnewtypeFoo=FooIntderivingP.PrimnewtypeinstanceU.MVectorsFoo=MV_Int (P.MVectorsFoo)
newtypeinstanceU.VectorFoo=V_Int (P.VectorFoo)
derivingvia (U.UnboxViaPrimFoo) instanceM.MVectorU.MVectorFooderivingvia (U.UnboxViaPrimFoo) instanceG.VectorU.VectorFooinstanceU.UnboxFoomain::IO()
main =doputStrLn"OK"pure()
but now the error is actually interesting and this is what made me create this PR:
$ cabal run Test.hs
/tmp/test/Test.hs:25:1: error:
• Couldn't match representation of type: P.Vector Foo
with that of: U.Vector (U.UnboxViaPrim Foo)
arising from a use of ‘ghc-prim-0.9.0:GHC.Prim.coerce’
NB: ‘U.Vector’ is defined in ‘Data.Vector.Unboxed.Base’
‘P.Vector’ is defined in ‘Data.Vector.Primitive’
The data constructor ‘Data.Vector.Unboxed.Base.V_UnboxViaPrim’
of newtype ‘U.Vector (U.UnboxViaPrim a)’ is not in scope
• In the expression:
ghc-prim-0.9.0:GHC.Prim.coerce
@(G.Mutable U.Vector s (U.UnboxViaPrim Foo)
-> GHC.ST.ST s (U.Vector (U.UnboxViaPrim Foo)))
@(G.Mutable U.Vector s Foo -> GHC.ST.ST s (U.Vector Foo))
(G.basicUnsafeFreeze @U.Vector @(U.UnboxViaPrim Foo))
In an equation for ‘G.basicUnsafeFreeze’:
G.basicUnsafeFreeze
= ghc-prim-0.9.0:GHC.Prim.coerce
@(G.Mutable U.Vector s (U.UnboxViaPrim Foo)
-> GHC.ST.ST s (U.Vector (U.UnboxViaPrim Foo)))
@(G.Mutable U.Vector s Foo -> GHC.ST.ST s (U.Vector Foo))
(G.basicUnsafeFreeze @U.Vector @(U.UnboxViaPrim Foo))
When typechecking the code for ‘G.basicUnsafeFreeze’
in a derived instance for ‘G.Vector U.Vector Foo’:
To see the code I am typechecking, use -ddump-deriv
In the instance declaration for ‘G.Vector U.Vector Foo’
|
25 | deriving via (U.UnboxViaPrim Foo) instance G.Vector U.Vector Foo
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/tmp/test/Test.hs:25:1: error:
• Couldn't match representation of type: P.Vector Foo
with that of: U.Vector (U.UnboxViaPrim Foo)
arising from a use of ‘ghc-prim-0.9.0:GHC.Prim.coerce’
NB: ‘U.Vector’ is defined in ‘Data.Vector.Unboxed.Base’
‘P.Vector’ is defined in ‘Data.Vector.Primitive’
The data constructor ‘Data.Vector.Unboxed.Base.V_UnboxViaPrim’
of newtype ‘U.Vector (U.UnboxViaPrim a)’ is not in scope
• In the expression:
ghc-prim-0.9.0:GHC.Prim.coerce
@(U.Vector (U.UnboxViaPrim Foo)
-> GHC.ST.ST s (G.Mutable U.Vector s (U.UnboxViaPrim Foo)))
@(U.Vector Foo -> GHC.ST.ST s (G.Mutable U.Vector s Foo))
(G.basicUnsafeThaw @U.Vector @(U.UnboxViaPrim Foo))
In an equation for ‘G.basicUnsafeThaw’:
G.basicUnsafeThaw
= ghc-prim-0.9.0:GHC.Prim.coerce
@(U.Vector (U.UnboxViaPrim Foo)
-> GHC.ST.ST s (G.Mutable U.Vector s (U.UnboxViaPrim Foo)))
@(U.Vector Foo -> GHC.ST.ST s (G.Mutable U.Vector s Foo))
(G.basicUnsafeThaw @U.Vector @(U.UnboxViaPrim Foo))
When typechecking the code for ‘G.basicUnsafeThaw’
in a derived instance for ‘G.Vector U.Vector Foo’:
To see the code I am typechecking, use -ddump-deriv
In the instance declaration for ‘G.Vector U.Vector Foo’
|
25 | deriving via (U.UnboxViaPrim Foo) instance G.Vector U.Vector Foo
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/tmp/test/Test.hs:25:1: error:
• Couldn't match representation of type: P.Vector Foo
with that of: U.Vector (U.UnboxViaPrim Foo)
arising from a use of ‘ghc-prim-0.9.0:GHC.Prim.coerce’
NB: ‘U.Vector’ is defined in ‘Data.Vector.Unboxed.Base’
‘P.Vector’ is defined in ‘Data.Vector.Primitive’
The data constructor ‘Data.Vector.Unboxed.Base.V_UnboxViaPrim’
of newtype ‘U.Vector (U.UnboxViaPrim a)’ is not in scope
• In the expression:
ghc-prim-0.9.0:GHC.Prim.coerce
@(U.Vector (U.UnboxViaPrim Foo) -> Int) @(U.Vector Foo -> Int)
(G.basicLength @U.Vector @(U.UnboxViaPrim Foo))
In an equation for ‘G.basicLength’:
G.basicLength
= ghc-prim-0.9.0:GHC.Prim.coerce
@(U.Vector (U.UnboxViaPrim Foo) -> Int) @(U.Vector Foo -> Int)
(G.basicLength @U.Vector @(U.UnboxViaPrim Foo))
When typechecking the code for ‘G.basicLength’
in a derived instance for ‘G.Vector U.Vector Foo’:
To see the code I am typechecking, use -ddump-deriv
In the instance declaration for ‘G.Vector U.Vector Foo’
|
25 | deriving via (U.UnboxViaPrim Foo) instance G.Vector U.Vector Foo
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/tmp/test/Test.hs:25:1: error:
• Couldn't match representation of type: P.Vector Foo
with that of: U.Vector (U.UnboxViaPrim Foo)
arising from a use of ‘ghc-prim-0.9.0:GHC.Prim.coerce’
NB: ‘U.Vector’ is defined in ‘Data.Vector.Unboxed.Base’
‘P.Vector’ is defined in ‘Data.Vector.Primitive’
The data constructor ‘Data.Vector.Unboxed.Base.V_UnboxViaPrim’
of newtype ‘U.Vector (U.UnboxViaPrim a)’ is not in scope
• In the expression:
ghc-prim-0.9.0:GHC.Prim.coerce
@(Int
-> Int
-> U.Vector (U.UnboxViaPrim Foo)
-> U.Vector (U.UnboxViaPrim Foo))
@(Int -> Int -> U.Vector Foo -> U.Vector Foo)
(G.basicUnsafeSlice @U.Vector @(U.UnboxViaPrim Foo))
In an equation for ‘G.basicUnsafeSlice’:
G.basicUnsafeSlice
= ghc-prim-0.9.0:GHC.Prim.coerce
@(Int
-> Int
-> U.Vector (U.UnboxViaPrim Foo)
-> U.Vector (U.UnboxViaPrim Foo))
@(Int -> Int -> U.Vector Foo -> U.Vector Foo)
(G.basicUnsafeSlice @U.Vector @(U.UnboxViaPrim Foo))
When typechecking the code for ‘G.basicUnsafeSlice’
in a derived instance for ‘G.Vector U.Vector Foo’:
To see the code I am typechecking, use -ddump-deriv
In the instance declaration for ‘G.Vector U.Vector Foo’
|
25 | deriving via (U.UnboxViaPrim Foo) instance G.Vector U.Vector Foo
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/tmp/test/Test.hs:25:1: error:
• Couldn't match representation of type: P.Vector Foo
with that of: U.Vector (U.UnboxViaPrim Foo)
arising from a use of ‘ghc-prim-0.9.0:GHC.Prim.coerce’
NB: ‘U.Vector’ is defined in ‘Data.Vector.Unboxed.Base’
‘P.Vector’ is defined in ‘Data.Vector.Primitive’
The data constructor ‘Data.Vector.Unboxed.Base.V_UnboxViaPrim’
of newtype ‘U.Vector (U.UnboxViaPrim a)’ is not in scope
• In the expression:
ghc-prim-0.9.0:GHC.Prim.coerce
@(U.Vector (U.UnboxViaPrim Foo)
-> Int
-> vector-stream-0.1.0.0:Data.Stream.Monadic.Box
(U.UnboxViaPrim Foo))
@(U.Vector Foo
-> Int -> vector-stream-0.1.0.0:Data.Stream.Monadic.Box Foo)
(G.basicUnsafeIndexM @U.Vector @(U.UnboxViaPrim Foo))
In an equation for ‘G.basicUnsafeIndexM’:
G.basicUnsafeIndexM
= ghc-prim-0.9.0:GHC.Prim.coerce
@(U.Vector (U.UnboxViaPrim Foo)
-> Int
-> vector-stream-0.1.0.0:Data.Stream.Monadic.Box
(U.UnboxViaPrim Foo))
@(U.Vector Foo
-> Int -> vector-stream-0.1.0.0:Data.Stream.Monadic.Box Foo)
(G.basicUnsafeIndexM @U.Vector @(U.UnboxViaPrim Foo))
When typechecking the code for ‘G.basicUnsafeIndexM’
in a derived instance for ‘G.Vector U.Vector Foo’:
To see the code I am typechecking, use -ddump-deriv
In the instance declaration for ‘G.Vector U.Vector Foo’
|
25 | deriving via (U.UnboxViaPrim Foo) instance G.Vector U.Vector Foo
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/tmp/test/Test.hs:25:1: error:
• Couldn't match representation of type: P.Vector Foo
with that of: U.Vector (U.UnboxViaPrim Foo)
arising from a use of ‘ghc-prim-0.9.0:GHC.Prim.coerce’
NB: ‘U.Vector’ is defined in ‘Data.Vector.Unboxed.Base’
‘P.Vector’ is defined in ‘Data.Vector.Primitive’
The data constructor ‘Data.Vector.Unboxed.Base.V_UnboxViaPrim’
of newtype ‘U.Vector (U.UnboxViaPrim a)’ is not in scope
• In the expression:
ghc-prim-0.9.0:GHC.Prim.coerce
@(G.Mutable U.Vector s (U.UnboxViaPrim Foo)
-> U.Vector (U.UnboxViaPrim Foo) -> GHC.ST.ST s ())
@(G.Mutable U.Vector s Foo -> U.Vector Foo -> GHC.ST.ST s ())
(G.basicUnsafeCopy @U.Vector @(U.UnboxViaPrim Foo))
In an equation for ‘G.basicUnsafeCopy’:
G.basicUnsafeCopy
= ghc-prim-0.9.0:GHC.Prim.coerce
@(G.Mutable U.Vector s (U.UnboxViaPrim Foo)
-> U.Vector (U.UnboxViaPrim Foo) -> GHC.ST.ST s ())
@(G.Mutable U.Vector s Foo -> U.Vector Foo -> GHC.ST.ST s ())
(G.basicUnsafeCopy @U.Vector @(U.UnboxViaPrim Foo))
When typechecking the code for ‘G.basicUnsafeCopy’
in a derived instance for ‘G.Vector U.Vector Foo’:
To see the code I am typechecking, use -ddump-deriv
In the instance declaration for ‘G.Vector U.Vector Foo’
|
25 | deriving via (U.UnboxViaPrim Foo) instance G.Vector U.Vector Foo
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/tmp/test/Test.hs:25:1: error:
• Couldn't match representation of type: P.Vector Foo
with that of: U.Vector (U.UnboxViaPrim Foo)
arising from a use of ‘ghc-prim-0.9.0:GHC.Prim.coerce’
NB: ‘U.Vector’ is defined in ‘Data.Vector.Unboxed.Base’
‘P.Vector’ is defined in ‘Data.Vector.Primitive’
The data constructor ‘Data.Vector.Unboxed.Base.V_UnboxViaPrim’
of newtype ‘U.Vector (U.UnboxViaPrim a)’ is not in scope
• In the expression:
ghc-prim-0.9.0:GHC.Prim.coerce
@(U.Vector (U.UnboxViaPrim Foo) -> U.UnboxViaPrim Foo -> b -> b)
@(U.Vector Foo -> Foo -> b -> b)
(G.elemseq @U.Vector @(U.UnboxViaPrim Foo))
In an equation for ‘G.elemseq’:
G.elemseq
= ghc-prim-0.9.0:GHC.Prim.coerce
@(U.Vector (U.UnboxViaPrim Foo) -> U.UnboxViaPrim Foo -> b -> b)
@(U.Vector Foo -> Foo -> b -> b)
(G.elemseq @U.Vector @(U.UnboxViaPrim Foo))
When typechecking the code for ‘G.elemseq’
in a derived instance for ‘G.Vector U.Vector Foo’:
To see the code I am typechecking, use -ddump-deriv
In the instance declaration for ‘G.Vector U.Vector Foo’
|
25 | deriving via (U.UnboxViaPrim Foo) instance G.Vector U.Vector Foo
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
finally if I fix this too I’ll get output
#!/usr/bin/env cabal
{- cabal:build-depends: , base , vector ^>= 0.13-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
moduleMainwhereimportqualifiedData.Vector.GenericasGimportqualifiedData.Vector.Generic.MutableasMimportqualifiedData.Vector.PrimitiveasPimportqualifiedData.Vector.UnboxedasUimportqualifiedData.Vector.Unboxed.BaseasUnewtypeFoo=FooIntderivingP.PrimnewtypeinstanceU.MVectorsFoo=MV_Int (P.MVectorsFoo)
newtypeinstanceU.VectorFoo=V_Int (P.VectorFoo)
derivingvia (U.UnboxViaPrimFoo) instanceM.MVectorU.MVectorFooderivingvia (U.UnboxViaPrimFoo) instanceG.VectorU.VectorFooinstanceU.UnboxFoomain::IO()
main =doputStrLn"OK"pure()
$ cabal run Test.hs
OK
I propose to amend doctest for UnboxViaPrim to make it working. I have also took liberty to sort imports and qualify imported module’s names in the same way doctest for IsoUnbox does for consistency (in a separate commit for ease of discarding it if it proves too controversial).
I don't remember why MVector is exported in full (so MV_UnboxViaPrim is in scope), but Vector isn't (and thus V_UnboxViaPrim isn't in scope). It's really unfortunate to push users to import Data.Vector.Unboxed.Base which does not even provide haddocks.
I don't remember why MVector is exported in full (...), but Vector isn't
It's always been like that 4c7bf23. It's difficult to say what are reasons though.
I think it would be better to add V_UnboxViaPrim to export list as was done for V_UnboxAs it wasn't added because of oversight. This way user won't be forced to import Data.Vector.Unboxed.Base
Updated, the only thing being not sure whether to export only V_UnboxViaPrim constructor or all constructors for Vector type family like it's done for MVector type family. I exported only one thing but inconsistency between exports of Vector and MVector bugs me.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The doctest examples for
UnboxViaPrim(https://hackage.haskell.org/package/vector-0.13.0.0/docs/Data-Vector-Unboxed.html#t:UnboxViaPrim) are not self-contained.When using one of them as-is
I get following error with GHC 9.4
After fixing qualified imports I try again with
but now the error is actually interesting and this is what made me create this PR:
finally if I fix this too I’ll get output
I propose to amend doctest for
UnboxViaPrimto make it working. I have also took liberty to sort imports and qualify imported module’s names in the same way doctest forIsoUnboxdoes for consistency (in a separate commit for ease of discarding it if it proves too controversial).