Opened 3 years ago

Last modified 17 months ago

#9079 new bug

Foreign.C.Types in haskell2010

Reported by: tensor5 Owned by:
Priority: normal Milestone:
Component: Core Libraries Version: 7.8.2
Keywords: Cc: core-libraries-committee@…, ekmett
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: #PRIME156 Differential Rev(s):
Wiki Page:


According to Haskell 2010, a marshallable foreign type has to be a newtype of a basic type with exposed constructor. Why constructors are not exposed in the module Foreign.C.Types from haskell2010? When I replace base with haskell2010 in

module Test where

import Foreign.C

foreign import ccall unsafe "sys/mount.h umount" umount :: CString -> IO CInt

I get

Unacceptable result type in foreign declaration: IO CInt
When checking declaration:
  foreign import ccall unsafe "static sys/mount.h umount" umount
    :: CString -> IO CInt

Change History (9)

comment:1 Changed 3 years ago by simonpj

Cc: core-libraries-committee@… added
Resolution: worksforme
Status: newclosed

Interesting. Foreign.C.Types does export CInt(..). And compiling the module you show works just fine for me:

bash$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.8.2

bash$ ghc -c T9079.hs -fforce-recomp
bash$ cat T9079.hs
module T9079 where

import Foreign.C

foreign import ccall unsafe "sys/mount.h umount" umount :: CString -> IO CInt

Perhaps you aren't using 7.8.2? I'll close as "worksforme" but if you disagree then please do re-open with more details.


comment:2 Changed 3 years ago by tensor5

I'm talking about compiling using haskell2010:

ghc -package haskell2010 -hide-package base Test.hs

As I see from this source the constructors for C types are not exposed.

comment:3 Changed 3 years ago by tensor5

Resolution: worksforme
Status: closednew

comment:4 Changed 3 years ago by hvr

I believe this is related to the breaking change that went into GHC 7.6.1:

Warning: newtype `CInt' is used in an FFI declaration,
         but its constructor is not in scope.
         This will become an error in GHC 7.6.1.

comment:5 Changed 3 years ago by simonpj

Well, this looks to me like a bug in the Haskell 2010 report

  • Section 8.4.2 says that newtypes must have their constructors visible, and claims that Foreign.C.Types follows this convention.
  • But Chapter 28 which shows Foreign.C.Types manifestly does not follow this convention.

That looks like an outright contradiction.

I think we should export all the data constructors in Foreign.C.Types in the haskell2010 package. Does anyone disagree?

Meanwhile, I'm adding Simon M to the cc list, as editor of the H2010 report.

Autin: could you act on this after a suitable delay?


comment:6 Changed 2 years ago by thoughtpolice

Component: libraries/haskell2010Core Libraries
Owner: set to ekmett

Moving over to new owning component 'Core Libraries'.

comment:7 Changed 2 years ago by ekmett

We've dropped core library support for the haskell2010 package, due to #9590, but this still seems actionable.

Herbert has been exploring ways to get users who really want it a fully compliant haskell2010 package, and this unfortunate contradiction seems like it'd still impact his efforts on that front.

comment:8 Changed 17 months ago by thomie

Owner: ekmett deleted

comment:9 Changed 17 months ago by hvr

Cc: ekmett added

See also #PRIME156

Note: See TracTickets for help on using tickets.