Changes between Version 2 and Version 3 of ObjectiveC/ForeignDeclarations

Apr 21, 2012 9:44:02 PM (3 years ago)



  • ObjectiveC/ForeignDeclarations

    v2 v3  
    77== Summary of foreign declarations == 
    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: 
     11=== Import === 
    1012 * Import an ObjC class (may be defined in Haskell): 
    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? 
    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. 
    1518 * Import of an ObjC selector (maybe synthesized from a property): 
    1720foreign import objc "<optional synthesize> <selector>" varid :: <type> 
    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: 
     25foreign import classConstructor objc "<constructor method name>" initializer 
     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... 
     29=== Export === 
     30 * Export a set of Haskell functions (pertaining to a certain datatype) as a class: 
     32foreign export class objc tycon <list of initializer> <list of method> 
     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 
     36... -> IO tycon 
     38 and `method`s look like 
     40tycon -> ... -> IO (tycon, b) 
    2042 * Export of a method implementation: