Is it possible to create PHP extensions in Haskell?

人走茶凉 提交于 2020-01-23 04:42:10

问题


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?


回答1:


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:

  • Call Haskell from C

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.




回答2:


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



来源:https://stackoverflow.com/questions/6030853/is-it-possible-to-create-php-extensions-in-haskell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!