Skip to content

Instantly share code, notes, and snippets.

@dminuoso

dminuoso/g.hs Secret

Last active August 18, 2022 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dminuoso/411af42513c3c97cdbd772de63fff805 to your computer and use it in GitHub Desktop.
Save dminuoso/411af42513c3c97cdbd772de63fff805 to your computer and use it in GitHub Desktop.
copyByteStringToByteArray :: BS.ByteString -> ByteArray
copyByteStringToByteArray (BS.PS fp off len) =
unsafeDupablePerformIO $
withForeignPtr fp $ \ptr -> do
mba <- newByteArray len
copyPtrToMutableByteArray mba 0 (ptr `plusPtr` off) len
unsafeFreezeByteArray mba
lib/Network/DNS/Pattern.hs:111:9: error:
• Ambiguous type variable ‘a0’ arising from a use of ‘copyPtrToMutableByteArray’
prevents the constraint ‘(Data.Primitive.Types.Prim
a0)’ from being solved.
Probable fix: use a type annotation to specify what ‘a0’ should be.
These potential instances exist:
instance Data.Primitive.Types.Prim Word8
-- Defined in ‘Data.Primitive.Types’
instance Data.Primitive.Types.Prim Char
-- Defined in ‘Data.Primitive.Types’
instance Data.Primitive.Types.Prim Double
-- Defined in ‘Data.Primitive.Types’
...plus three others
...plus 70 instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In a stmt of a 'do' block:
copyPtrToMutableByteArray mba 0 (ptr `plusPtr` off) len
In the expression:
do mba <- newByteArray len
copyPtrToMutableByteArray mba 0 (ptr `plusPtr` off) len
unsafeFreezeByteArray mba
In the second argument of ‘($)’, namely
‘\ ptr
-> do mba <- newByteArray len
copyPtrToMutableByteArray mba 0 (ptr `plusPtr` off) len
....’
|
111 | copyPtrToMutableByteArray mba 0 (ptr `plusPtr` off) len
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/Network/DNS/Pattern.hs:111:50: error:
• Found type wildcard ‘_’ standing for ‘Ptr Word8’
To use the inferred type, enable PartialTypeSignatures
• In an expression type signature: _
In the first argument of ‘plusPtr’, namely ‘(ptr :: _)’
In the third argument of ‘copyPtrToMutableByteArray’, namely
‘((ptr :: _) `plusPtr` off)’
• Relevant bindings include
mba :: Data.Primitive.ByteArray.MutableByteArray
ghc-prim-0.7.0:GHC.Prim.RealWorld
(bound at lib/Network/DNS/Pattern.hs:110:9)
ptr :: Ptr Word8 (bound at lib/Network/DNS/Pattern.hs:109:28)
len :: Int (bound at lib/Network/DNS/Pattern.hs:107:41)
off :: Int (bound at lib/Network/DNS/Pattern.hs:107:37)
fp :: GHC.ForeignPtr.ForeignPtr Word8
(bound at lib/Network/DNS/Pattern.hs:107:34)
copyByteStringToByteArray :: BS.ByteString -> ByteArray
(bound at lib/Network/DNS/Pattern.hs:107:1)
|
111 | copyPtrToMutableByteArray mba 0 ((ptr :: _) `plusPtr` off) len
| ^
lib/Network/DNS/Pattern.hs:111:65: error:
• Found type wildcard ‘_’ standing for ‘Ptr b’
Where: ‘b’ is a rigid type variable bound by
the inferred type of <expression> :: Ptr b
at lib/Network/DNS/Pattern.hs:111:65
To use the inferred type, enable PartialTypeSignatures
• In an expression type signature: _
In the third argument of ‘copyPtrToMutableByteArray’, namely
‘((ptr `plusPtr` off) :: _)’
In a stmt of a 'do' block:
copyPtrToMutableByteArray mba 0 ((ptr `plusPtr` off) :: _) len
• Relevant bindings include
mba :: Data.Primitive.ByteArray.MutableByteArray
ghc-prim-0.7.0:GHC.Prim.RealWorld
(bound at lib/Network/DNS/Pattern.hs:110:9)
ptr :: Ptr Word8 (bound at lib/Network/DNS/Pattern.hs:109:28)
len :: Int (bound at lib/Network/DNS/Pattern.hs:107:41)
off :: Int (bound at lib/Network/DNS/Pattern.hs:107:37)
fp :: GHC.ForeignPtr.ForeignPtr Word8
(bound at lib/Network/DNS/Pattern.hs:107:34)
copyByteStringToByteArray :: BS.ByteString -> ByteArray
(bound at lib/Network/DNS/Pattern.hs:107:1)
|
111 | copyPtrToMutableByteArray mba 0 ((ptr `plusPtr` off) :: _) len
|
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment