Opened 8 years ago

Last modified 2 years ago

#3541 new feature request

Allow local foreign imports

Reported by: mokus Owned by: DevarshDesai
Priority: normal Milestone:
Component: Compiler (FFI) Version: 6.12.2
Keywords: newcomer Cc: omeragacan@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

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 (6)

comment:1 Changed 8 years ago by igloo

difficulty: Unknown
Milestone: 6.14.1

comment:2 Changed 8 years ago by simonmar

difficulty: UnknownModerate (1 day)
Milestone: 6.14.1_|_

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

comment:3 Changed 8 years ago by simonmar

difficulty: Moderate (1 day)Moderate (less than a day)

comment:4 Changed 2 years ago by thomie

Keywords: newcomer added
Type of failure: None/Unknown

comment:5 Changed 2 years ago by DevarshDesai

Owner: set to DevarshDesai
Version: 6.10.46.12.2

comment:6 Changed 2 years ago by osa1

Cc: omeragacan@… added
Note: See TracTickets for help on using tickets.