[GHC] #11670: Can't infer type

GHC ghc-devs at haskell.org
Thu Mar 3 08:53:53 UTC 2016


#11670: Can't infer type
-------------------------------------+-------------------------------------
           Reporter:  Iceland_jack   |             Owner:
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  7.10.3
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 {{{#!hs
 {-# 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 at 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

 {{{#!hs
 {-# 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?

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11670>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list