[clean-list] Foreign modules

Tomasz Zielonka t.zielonka@students.mimuw.edu.pl
Mon, 15 Jul 2002 07:30:11 +0200


Hi!

I noticed that in Clean 2.0.1 for Unix in the iolib library bindings for
C libraries are generated from 'foreign module' (fcl) files using fclc
program. 

Having read how Clean's Uniqueness Typing allows to easily interface
with imperative foreign code, I expected that bindings generated by fclc
should use UT. They don't.

I've made a simple example which clearly shows that generated bindings
for C functions are not purely functional. 

x.fcl:
  foreign module x;
  int kill(int,int)                       'Kill';

fclc generates such declarations this foreign module:

x.dcl:
  system module x;
  Kill :: !Int !Int -> Int;

When I use Kill in my program, underlying kill(2) system call is
executed only when the value produced by Kill is needed for
computations. This is a side effect but it doesn't "change the World".
It is difficult to control Kill's behaviour.

I expected rather something like:
  Kill :: !Int !Int !*World -> (Int, *World)

To Clean Team: 
  Did you decide that threading World through all foreign function calls
  would be to tiring and so you chose "simplicity" for purity (and
  correctness maybe)? 

  Maybe the C library you were interfacing to was already purely
  functional?

  Is fclc recommended for doing FFI in Clean?

Please explain it to me. 
Perhaps I'm making some error in my thinking.

Best regards,
Tom

-- 
.signature: Too many levels of symbolic links