Generalisation behaviour of partial type signatures
{-# LANGUAGE InstanceSigs, PartialTypeSignatures #-}
import Foreign.C.Types
import Foreign.Storable
import Foreign.Ptr
data CTimeval = MkCTimeval CLong CLong
peek :: Ptr CTimeval -> IO CTimeval
peek ptr = do
s <- peekElemOff (castPtr ptr) 0 :: _ _
mus <- peekElemOff (castPtr ptr) 1
return (MkCTimeval s mus)
Fails with
baldur@Loki:~$ ghci -ignore-dot-ghci /tmp/tLcV.hs
GHCi, version 8.1.20160117: http://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Main ( /tmp/tLcV.hs, interpreted )
/tmp/tLcV.hs:11:10: error:
• No instance for (Storable t)
Possible fix:
add (Storable t) to the context of
an expression type signature:
IO t
• In a stmt of a 'do' block:
s <- peekElemOff (castPtr ptr) 0 :: _ _
In the expression:
do { s <- peekElemOff (castPtr ptr) 0 :: _ _;
mus <- peekElemOff (castPtr ptr) 1;
return (MkCTimeval s mus) }
In an equation for ‘peek’:
peek ptr
= do { s <- peekElemOff (castPtr ptr) 0 :: _ _;
mus <- peekElemOff (castPtr ptr) 1;
return (MkCTimeval s mus) }
Failed, modules loaded: none.
while
{-# LANGUAGE InstanceSigs, PartialTypeSignatures #-}
import Foreign.C.Types
import Foreign.Storable
import Foreign.Ptr
data CTimeval = MkCTimeval CLong CLong
peek :: Ptr CTimeval -> IO CTimeval
peek ptr = do
s <- peekElemOff (castPtr ptr) 0 :: _ CLong
mus <- peekElemOff (castPtr ptr) 1
return (MkCTimeval s mus)
succeeds. Is this expected?
Trac metadata
Trac field | Value |
---|---|
Version | 7.10.3 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |