Opened 5 years ago

Last modified 4 years ago

#3541 new feature request

Allow local foreign imports

Reported by: mokus Owned by:
Priority: normal Milestone:
Component: Compiler (FFI) Version: 6.10.4
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Moderate (less than a day)
Test Case: Blocked By:
Blocking: Related Tickets:

Description

I have no idea the level of difficulty this would entail, but it would be rather nice to be able to import foreign functions at scopes other than the top level. When writing glue code, especially for C++ where I often want to catch and haskellize exceptions, I find myself using wrappers quite a bit, for example:

foreign import ccall "foo.h foo" 
    raw_foo :: CString -> IO ()
foo :: String -> IO ()
foo s = withCString s raw_foo

Where I only want "foo" exported from the module. It's not that big a deal to list explicit exports, I know, but I would like to be able to say instead:

foo :: String -> IO ()
foo s = withCString s raw_foo
    where
        foreign import ccall "foo.h foo" raw_foo :: CString -> IO ()

In addition to reducing clutter in the top level namespace, it makes for less clutter on the left margin of the code, making it easier to scan through function names visually.

Change History (3)

comment:1 Changed 4 years ago by igloo

  • Difficulty set to Unknown
  • Milestone set to 6.14.1

comment:2 Changed 4 years ago by simonmar

  • Difficulty changed from Unknown to Moderate (1 day)
  • Milestone changed from 6.14.1 to _|_

Let's leave this as an unmilestoned feature request for now. It's something that a contributor could tackle.

comment:3 Changed 4 years ago by simonmar

  • Difficulty changed from Moderate (1 day) to Moderate (less than a day)
Note: See TracTickets for help on using tickets.