Changes between Version 2 and Version 3 of ObjectiveC/ForeignDeclarations


Ignore:
Timestamp:
Apr 21, 2012 9:44:02 PM (3 years ago)
Author:
amarqueslee
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ObjectiveC/ForeignDeclarations

    v2 v3  
    77== Summary of foreign declarations ==
    88
    9 The following declarations specific to Objective-C:
     9With the current FFI we supply definitions to marshal foreign functions and basic types. Since this extension relates to classes, and since there's lots of OO languages out there, it would be nice to set the extension up in such a way that other OO FFI extensions look like it. Keeping this in mind, working with Obj-C classes in Haskell might look like:
     10
     11=== Import ===
    1012 * Import an ObjC class (may be defined in Haskell):
    1113{{{
    12 foreign class objc "<optional header> <optional implementation> <class name>" tycon
     14foreign import class objc "<optional header> <optional implementation> <class name>" tycon -- As a starting point, maybe derive the tycon from the class name?
    1315}}}
    1416  The newly introduced type `tycon` can be marshalled to and from ObjC land; i.e., it is a ''foreign type'' in the sense of Section 3.2 of the Haskell FFI.
     17
    1518 * Import of an ObjC selector (maybe synthesized from a property):
    1619{{{
    1720foreign import objc "<optional synthesize> <selector>" varid :: <type>
    1821}}}
    19   there can be more than one foreign import declaration for one selector with different Haskell identifiers and types.
     22  there can be more than one foreign import declaration for one selector with different Haskell identifiers and types. Note that, in the worst case we could just provide a function of type `String -> IO ObjCSel`, since Objective-C selectors are completely type-unsafe anyway.
     23 * Import an ObjC constructor:
     24{{{
     25foreign import classConstructor objc "<constructor method name>" initializer
     26}}}
     27Note that for Objective-C we can get away without a separate constructor by calling methods on classes. However, it's a nice-to-have as part of bridging to OO languages. Perhaps we can also build in memory management for objects returned from these tagged constructors...
     28
     29=== Export ===
     30 * Export a set of Haskell functions (pertaining to a certain datatype) as a class:
     31{{{
     32foreign export class objc tycon <list of initializer> <list of method>
     33}}}
     34 The Haskell-defined `tycon` would be type-constrained to have certain properties (yet to be specified). `initializer`s are used to provide constructors of the form
     35{{{
     36... -> IO tycon
     37}}}
     38 and `method`s look like
     39{{{
     40tycon -> ... -> IO (tycon, b)
     41}}}
    2042 * Export of a method implementation:
    2143{{{