将Haskell程序作为C源分发 [英] Distributing a Haskell program as C source

查看:80
本文介绍了将Haskell程序作为C源分发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个Haskell程序或库,我想让非Haskeller开发者(可能是C程序员)访问.我可以使用GHC将其编译为C,然后将其作为C源分发吗?

Say I have a Haskell program or library that I'd like to make accessible to non-Haskellers, potentially C programmers. Can I compile it to C using GHC and then distribute this as a C source?

如果可能的话,有人可以提供一个最小的例子吗? (例如Makefile)

If this is possible, can someone provide a minimal example? (e.g., a Makefile)

是否可以使用GHC自动确定需要哪些编译器标志和标头,然后将其捆绑到一个文件夹中?

Is it possible to use GHC to automatically determine what compiler flags and headers and needed, and then perhaps bundle this into a single folder?

基本上,我对能够用C和Haskell编写程序的一部分,然后将其分发为tarball感兴趣,但不需要目标安装GHC和Cabal.

Basically I'm interested in being able to write portions of programs in C and Haskell, and then distributing it as a tarball, but without requiring the target to have GHC and Cabal installed.

推荐答案

我有兴趣能够用C和Haskell编写部分程序,然后将其作为tarball分发,但不需要目标安装GHC和Cabal.

I'm interested in being able to write portions of programs in C and Haskell, and then distributing it as a tarball, but without requiring the target to have GHC and Cabal installed.

您要的是很多不太可能找到的基础架构.请记住,任何Haskell程序,即使将要编译为C程序,也几乎可以肯定要依靠大型,复杂的运行时系统来正确运行.该运行时系统至少必须支持垃圾回收和惰性评估.因此,您不仅有翻译问题.

You're asking for an awful lot of infrastructure that you're unlikely to find. Remember that any Haskell program, even if it is going to be compiled to C, is almost certain to depend on a large, complex run-time system for its correct operation. At a bare minimum, that run-time system has to support garbage collection and lazy evaluation. So you have more than just a translation problem.

我建议您将这个问题作为软件分发问题来解决.为您喜欢的发行平台(Debian,Red Hat,InstallShield等)提供一个软件包,而不是压缩包.就个人而言,为了重用其他人的工作,我的目标是检查Cabal,在需要时安装Cabal,然后使用Cabal安装其余用户需要的东西.

I suggest you tackle this problem as a software-distribution problem. Rather than a tarball, provide a package for your favored distribution platform (Debian, Red Hat, InstallShield, whatever). Personally, in order to reuse other people's efforts, I would aim for something that checks for Cabal, installs Cabal if needed, then uses Cabal to install the rest of what your users will need.

这篇关于将Haskell程序作为C源分发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆