Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,970
    • Issues 4,970
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 461
    • Merge requests 461
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Wiki
  • Objective c
  • foreign declarations

foreign declarations · Changes

Page history
Edit ObjectiveC/ForeignDeclarations authored Apr 23, 2012 by amarqueslee's avatar amarqueslee
Hide whitespace changes
Inline Side-by-side
objective-c/foreign-declarations.md
View page @ 023af031
...@@ -28,34 +28,34 @@ With the current FFI we supply definitions to marshal foreign functions and basi ...@@ -28,34 +28,34 @@ With the current FFI we supply definitions to marshal foreign functions and basi
- Import an ObjC constructor: - Import an ObjC constructor:
```wiki ```wiki
foreign import classConstructor objc "<constructor method name>" initializer foreign import constructor objc "<constructor method name>" initializerName
``` ```
Note 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... Note 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. Ambitiously, perhaps we could also build in memory management for objects returned from these tagged constructors...
### Export ### Export
- Export a set of Haskell functions (pertaining to a certain datatype) as a class: - Export a set of Haskell functions (pertaining to a certain datatype) as a class:
```wiki ```wiki
foreign export class objc tycon "<superclass>" <list of initializer> <list of method> foreign export constructor objc tycon "<superclass> <class>" constructor :: ... -> IO tycon
``` ```
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 The Haskell-defined `tycon` would be type-constrained to have certain properties (yet to be specified).
- Export of a method implementation:
```wiki ```wiki
... -> IO tycon foreign export method objc "<optional header> +/-[<class> <selector>]" methodid :: <type>
``` ```
and `method`s look like where
```wiki ```wiki
ObjCPtr super -> tycon -> ... -> IO (tycon, b) methodid :: ObjCPtr super -> tycon -> ... -> IO (tycon, b)
``` ```
This approach would pull in `superclass` as a side-effect, and client code could work with it, for now pretending it's some unrelated class. This should give method implementations an Objective-C feel. This approach would provide opaque access to the object's Objective-C representation as an opaque supertype, giving Haskell method implementations an Objective-C feel.
- Export of a method implementation:
```wiki
foreign export objc "<optional header> +/-[<class> <selector>]" varid :: <type> In both of these cases, the underlying structure of the class' datatype - if possible - should be derived from the provided type constructor.
```
\ No newline at end of file
Clone repository Edit sidebar
  • 9.6
  • Adventures in GHC compile times
  • All things layout
  • AndreasK
  • AndreasPK
  • Back End and Run Time System
  • Backpack refactoring
  • Backpack units
  • Brief Guide for Compiling GHC to iOS
  • Building GHC on Windows with Stack protector support (SSP) (using Make)
  • CAFs
  • CafInfo rework
  • Compiling Case Expressions in ghc
  • Compiling Data.Aeson Error
  • Contributing a Patch
View All Pages