Is it possible to create PHP extensions in Haskell?
Asked Answered
S

2

12

Is it possible to create PHP extensions with Haskell?

Usually PHP extensions are written using C. Is using Haskell FFI to provide functionality for a stub C extension possible (or even a good idea)?

What are the caveats to such an approach? Does Zend perform some magic in the background that would disrupt such a scheme?

Spice answered 17/5, 2011 at 12:36 Comment(2)
Oh the haskell fanboys will love this idea!Deeplaid
We do, but not quite as much as replacing PHP with HaskellInstruct
C
7

You can certainly do this, though I'm not sure anyone has tried. Haskell interoperates with C via its FFI mechanism, and you can certainly:

so if you can call C from PHP, and that C calls Haskell, you're in business.


Why would you want to do this? Faster, safer, simple code for your core algorithms or safety-critical code, perhaps. Or to take advantage of say, a parallel or multicore server backend via Haskell.

Caroche answered 17/5, 2011 at 16:50 Comment(1)
Well in this case, because I already have a Haskell program that I currently call using shell_exec from PHP. Now we are moving towards PHP extensions, so I am trying to save the existing codebase (atleast in the short run before I have had a chance to convert it to C). Not to mention how much more painful C is compared to Haskell (or anything for that matter).Spice
B
1

Yes, its possible. Just make sure you wrap everything and translate arguments between php -> c -> haskell and the way back correctly.

Barksdale answered 17/5, 2011 at 12:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.