在Android操作系统上运行一个Haskell程序操作系统、程序、Android、Haskell

2023-09-05 05:22:47 作者:孤芳又自赏

Forenote:这是线程的扩展开始 /转/哈斯克尔的

Forenote: This is an extension of the thread started on /r/haskell

让我们开始与事实:

Android的一个真棒操作系统 在Haskell是这个星球上的最好的编程语言

因此​​,很显然,他们的结合会使得Android开发好得多。所以基本上我只是想知道我怎么能写Haskell程序为Android操作系统。我的问题是:

Therefore, clearly, combining them would make Android development that much better. So essentially I would just like to know how I can write Haskell programs for the Android OS. My question is:

我怎样才能得到一个Haskell程序执行/在Android操作系统上运行?

How can I get a Haskell program to execute/run on the Android OS?

P.S。忽略上面的笑话,因为这是一个诚实的问题,我真的很希望看到这种情况发生。

P.S. Ignore the jokes above because this is an honest question and I really would like to see this happen.

推荐答案

您如何做到这一点是首先让Haskell编译器,可以目标C的Andr​​oid NDK,它有一个GCC端口的ARM架构。 JHC可以平凡做到这一点与描述平台(字的大小,C编译器等),我已经与Wii的自制软件开发工具包做这是一个非常小的INF样式文件,这是很容易的。然而JHC仍然有一些稳定性问题复杂code,如使用带有IO一个单子变压器栈,但JHC一直在提高了很多,在过去6个月。世界上只有一个人工作JHC我只是希望更多的人能帮助他。

How you do it is by first getting a Haskell compiler which can target C with the android NDK which comes with a GCC port for ARM architectures. JHC can trivially do this with a very small inf style file which describes the platform (word size, c-compiler, etc) I've done this with the Wii homebrew dev kit and it was quite easy. However jhc still has some stability issues with complex code such as using a monad transformer stack with IO but jhc has been improving a lot over the last 6 months. There is only one person working on JHC I just wished more people could help him.

另一种选择是建立GHC针对NDK GCC的未注册的端口,这是很多更复杂的过程,因为GHC是不是真正的交叉编译器的时刻,你需要了解构建系统哪些部位你需要改变。另一种选择是NHC它可以交叉编译为C,像GHC你需要建立NHC针对C编译器,NHC没有多少Haskell的扩展,像GHC。

The other option is to build an "unregistered" port of GHC targeting the ndk gcc, this is a lot more involved process because GHC is not a true cross-compiler at the moment and you need to understand the build system what parts you need to change. Another option is NHC which can cross-compile to C, like GHC you need to build nhc targeting a C compiler, NHC does not have many Haskell extensions like GHC.

一旦你有Haskell编译针对NDK GCC,你需要编写绑定要么在Android NDK JNI胶code框架(由于Android 2.3加入),或者你必须编写JNI胶$ C $的Java-C C之间-Haskell,选择前者是简单的解决方案,如果我没记错的话,实际上可能与Android低于2.3 previous版本向后兼容。

Once you have Haskell compiler targeting NDK GCC, you will need to write bindings to either the android NDK JNI glue code framework (added since android 2.3) or you must write JNI glue code between Java-C-Haskell, the former option is the easier solution and if I remember correctly might actually be backwards compatible with previous versions of Android below 2.3.

一旦你有了这个,你必须建立哈斯克尔code作为共享库或者静态库,被链接到NDK的java胶code(这本身就是一个共享库)。据我所知,你不能正式在Android上运行本地可执行文件。你也许可以用一个根深蒂固的手机做到这一点,所以我想这意味着你不能分发在App Store机可执行即使在NDK GCC端口可以产生本地可执行文件就好了。这也可能杀死使用LLVM,除非你能得到NDK JNI正与LLVM的选项。

Once you have this you must build Haskell code as shared library or static library which gets linked into the NDK java glue code (which itself is a shared library). As far as I'm aware you can not officially run native executables on android. You could probably do it with a rooted phone, thus I assume this means you can not distribute native executables on the app store even when the NDK gcc port can generate native executables just fine. This also probably kills the option for using LLVM unless you can get the NDK JNI working with LLVM.

目前最大的障碍是没有这么多得到一个Haskell编译为Android(这仍然是一个很大的障碍),最大的问题是,有些人需要写绑定API的NDK库,这是一个巨大的任务,形势更糟,如果你需要写的Andr​​oid UI code,因为没有NDK的API,这部分Android SDK的。如果你想要做的Andr​​oid UI code在Haskell有人将不得不通过JNI / C写的Haskell绑定到Java。除非有一个更加自动化的过程,写绑定库(我知道有一些,他们只是没有自动足以让我),然后另外一个人做的可能性是相当低的。

The biggest hurdle isn't so much of getting a Haskell compiler for android (which is still a big hurdle) the biggest problem is that some one needs to write binding APIs for NDK libraries which is a huge task and the situation is worse if you need to write android UI code because there are no NDK APIs for this part of the android SDK. If you want to do android UI code in Haskell somebody will have to write Haskell bindings to Java through JNI/C. Unless there is a more automated process to writing binding libraries (I know there are some, they are just not automated enough for me) then chances of some one doing it are quite low.

L01man:是否有关于如何做到这一点的教程?为了   第一部分,我明白我必须下载JHC。我有什么要   写在inf文件,以及如何使用它?

L01man: Is there a tutorial about how to do this? For the first part, I understand I have to download JHC. What do I have to write in the inf file and how to use it?

请注意,在我回答这个问题,我没有用JHC相当一段时间,因为我最初写这一点,新版本已被释放,因为这样我不知道JHC目前如何稳定是当它涉及到code代的更复杂的Haskell程序。这是你考虑才作出了大量的Haskell程序与JHC,在你走之前完全在你应该做一些小测试,警告任何人。

Please note before I answer this question I haven't used jhc for quite sometime since I originally wrote this and newer versions have been released since so I do not know how stable jhc currently is when it comes to code generation of more complex Haskell programs. This is a warning to anyone before you consider making a large Haskell program with JHC, you should do some small tests before you go full on.

JHC确实有一个手动 http://repetae.net/computer/jhc/manual.html 并一节的建立交叉编译和.ini文件选项:http://repetae.net/computer/jhc/manual.html#crosscompilation.

jhc does have a manual http://repetae.net/computer/jhc/manual.html and a section on setting-up cross-compilation and .ini file with options: http://repetae.net/computer/jhc/manual.html#crosscompilation.

L01man:第二部分是一种替代第一个。我不知道该怎么做,你在说什么   第三位。

环境安装并运行第一个Android程序

L01man: The second part is an alternative to the first. I don't know how to do what you said in the third.

在开始之前,你应该拥有的C有一定的了解,并熟悉使用Haskell的外部函数接口(FFI)和工具,如hs2c。你也应该熟悉使用Android NDK和建设的apk共享库。你需要知道这些C-哈斯克尔,的Java / C-哈斯克尔之间的接口,开发Haskell程序为Android,你可以正式分发/销售市场上的商店。

Before you begin you should have some knowledge of C and be comfortable with using the Haskell foreign function interface (FFI) and tools such as hs2c. You should also be familiar with using the Android NDK and building .apk with shared libraries. You will need to know these to interface between C-Haskell, Java/C-Haskell and develop Haskell programs for Android that you can officially distribute/sell on the market store.

L01man:据我所知,它的目标是创建一个具有约束力的   Android的API。但是......请问第四部分说,我们不能让.apk文件用   哈斯克尔?

L01man: I understand that its goal is to create a binding for the Android API. But... does the 4th part says we can't make .apk with Haskell?

.apk文件仅仅是一个应用程序包文件格式,是建立与配备了Android SDK(不NDK)的工具,这有很少做构建二进制文件本身。 Android包可以包含本地共享库,这就是你的Haskell程序将会和通过Android NDK生成的本机共享/静态库。

.apk is just an app package file format and is built with the tools that come with the Android SDK (not NDK), this has very little to do building the binaries itself. Android packages can contain native shared libraries, this what your Haskell program will be and the native shared/static libraries are generated via the Android NDK.