<commit_before>Notes on the Foreign Function Interface (ffi) - 12 Feb 2001


This release includes a partial implementation of the Haskell foreign
function interface definition:
  
  http://www.haskell.org/hdirect/ffi.html
  http://www.haskell.org/hdirect/ffi-a4.ps.gz
  http://www.haskell.org/hdirect/ffi-letter.ps.gz
  http://www.haskell.org/hdirect/ffi-a4.dvi.gz
  http://www.haskell.org/hdirect/ffi-letter.dvi.gz

with two minor caveats (excruciating details appended at the end):

o "foreign export static" is not implemented but, fortunately, this is
  one of the least used parts of the ffi and can be worked around.

o "foreign export dynamic" is implemented but only for the x86
  architecture but it should be easy to port by any experienced
  assembly language programmer.



Suppose you have some C functions in foo/test.c and some ffi
declarations for those functions in foo/Test.hs, you can use them with
Hugs as follows:

  # Generate Test.c (note that it is _not_ foo/test.c)
  #
  # [For every Haskell file loaded which contains ffi declarations,
  # this will generate a .c file _in the current working directory_.]
  hugs +G Test.hs

  # Compile and partially link Test.c and foo/test.c putting the
  # result in foo/Test.so.
  #
  # Details on how to partially link files vary from one platform to
  # another.
  cc -shared Test.c foo/test.c -o foo/Test.so

  # Run Hugs as normal - when foo/Test.hs is loaded, it will load foo/Test.so
  hugs foo/Test.hs

  # And now try using the imported or exported functions.



Enjoy!

--
<NAME>        <EMAIL>        http://www.cs.utah.edu/~reid/
<commit_msg>Added an example of .so file generation under MacOS X, and simplified the example filenames somewhat.<commit_after>Notes on the Foreign Function Interface (ffi) - 12 Feb 2001


This release includes a partial implementation of the Haskell foreign
function interface definition:
  
  http://www.haskell.org/hdirect/ffi.html
  http://www.haskell.org/hdirect/ffi-a4.ps.gz
  http://www.haskell.org/hdirect/ffi-letter.ps.gz
  http://www.haskell.org/hdirect/ffi-a4.dvi.gz
  http://www.haskell.org/hdirect/ffi-letter.dvi.gz

with two minor caveats (excruciating details appended at the end):

o "foreign export static" is not implemented but, fortunately, this is
  one of the least used parts of the ffi and can be worked around.

o "foreign export dynamic" is implemented but only for the x86
  architecture but it should be easy to port by any experienced
  assembly language programmer.



Suppose you have some C functions in test.c and some ffi
declarations for those functions in Test.hs, you can use them with
Hugs as follows:

  # Generate Test.c (note that it is _not_ test.c)
  #
  # [For every Haskell file loaded which contains ffi declarations,
  # this will generate a .c file _in the current working directory_.]
  hugs +G Test.hs

  # Compile and partially link Test.c and test.c putting the
  # result in Test.so.
  #
  # Details on how to partially link files vary from one platform to
  # another.
  cc -shared Test.c test.c -o Test.so                     # Most Unixen
  cc -bundle -undefined suppress Test.c test.c -o Test.so # MacOS X

  # Run Hugs as normal - when Test.hs is loaded, it will load Test.so
  hugs Test.hs

  # And now try using the imported or exported functions.



Enjoy!

--
<NAME>        <EMAIL>        http://www.cs.utah.edu/~reid/

{'fraction_non_alphanumeric': 0.07939787485242031, 'fraction_numerical': 0.0059031877213695395, 'mean_word_length': 3.1839506172839505, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 12, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6842482', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1034, 'n_words': 431}