[Haskell-cafe] Issues with IO and FFIs

Bulat Ziganshin bulat.ziganshin at gmail.com
Wed Apr 22 06:22:25 EDT 2009


Hello Jon,

Wednesday, April 22, 2009, 1:54:58 PM, you wrote:

> Does anyone have any comments on the following criticism of some difficulties
> with FFI, including IO, in Haskell:

> http://groups.google.com/group/comp.lang.functional/msg/6d650c086b2c8a49?hl=en

> In particular, is it not always possible to write IO libraries safely in
> Haskell?

i think that this letter is true on factual part but he exaggerate
this problem

1) you can develop any pure-haskell imperative library with safe (no global
state) interface and implementation. well, you can do the same with
any other language too :)

2) if you are going to hardware level, it usually has von Neumann
architecture, i.e. global state. so when providing some service to
application, you have to deal with global state at some level. if it
doesn't handled at C level (in his example, MVar may be maintained at C
side), you need to to this at Haskell level

3) haskell language still doesn't provide features to create global
variables, although it was proposed to add syntax he uses:

globalLock <- newMVar False
-- the same as globalLock = unsafePerformIO (newMVar False)
-- but with guarantees of no sharing

so we use unsafePerformIO hack instead


that's all. if we sometimes deal with global-state C libraries, we may
need to use global vars too. anyway, at some level (be it C or
Haskell) we need to create safe interface too unsafe von Neumann
hardware


-- 
Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com



More information about the Haskell-Cafe mailing list