小编Dan*_*itz的帖子

在交叉编译haskell代码时如何安装依赖项?

我已经成功创建了一个ghc交叉编译器,它允许我从我的x64 linux机器编译armv6h的haskell代码(在我的例子中是raspberry pi).我已成功在树莓上运行了一个hello world程序.

不,我想构建我真正的应用程序,它对其他haskell模块有很多依赖.当我为x64编译时,我就是这么做的

cabal install dependenciy1 depenency2 ...
Run Code Online (Sandbox Code Playgroud)

我知道我可以让我自己的程序成为一个cabal项目,自动完成这一步.但这不是重点.

当我尝试使用交叉编译器时

arm-unknown-linux-gnueabi-ghc --make myapp.hs
Run Code Online (Sandbox Code Playgroud)

它告诉我它找不到的模块.当然,他们没有安装!

我阅读https://ghc.haskell.org/trac/ghc/wiki/Building/CrossCompiling 并根据我尝试过

cabal --with-ghc=arm-unknown-linux-gnueabi-ghc --with-ghc-pkg=arm-unknown-linux-gnueabi-ghc-pkg --with-ld=arm-unknown-linux-gnueabi-ld install random
Run Code Online (Sandbox Code Playgroud)

随机是我正在尝试安装的依赖性.我收到以下错误:

Resolving dependencies...
Configuring random-1.0.1.3...
Failed to install random-1.0.1.3
Last 10 lines of the build log ( /home/daniel/.cabal/logs/random-1.0.1.3.log ):
/home/daniel/.cabal/setup-exe-cache/setup-Cabal-1.18.1.3-arm-linux-ghc-7.8.3.20140804: /home/daniel/.cabal/setup-exe-cache/setup-Cabal-1.18.1.3-arm-linux-ghc-7.8.3.20140804:      cannot execute binary file
cabal: Error: some packages failed to install:
random-1.0.1.3 failed during the configure step. The exception was:
ExitFailure 126
Run Code Online (Sandbox Code Playgroud)

当我做

file /home/daniel/.cabal/setup-exe-cache/setup-Cabal-1.18.1.3-arm-linux-ghc-7.8.3.20140804
Run Code Online (Sandbox Code Playgroud)

我明白了

/home/daniel/.cabal/setup-exe-cache/setup-Cabal-1.18.1.3-arm-linux-ghc-7.8.3.20140804: ELF 32-bit LSB executable, ARM, EABI5 version …
Run Code Online (Sandbox Code Playgroud)

haskell cross-compiling ghc cabal-install raspberry-pi

15
推荐指数
1
解决办法
1170
查看次数

Haskell:有没有办法从函数内部推导函数的返回类型?

假设我有以下功能:

import Data.Typeable
import Text.Read (reads)

parse :: (Read b, Typeable b) => String -> IO b
parse msg = case reads msg of
        [(value,"")] -> return value
        _ -> throwIO $ ErrorCall ("could not parse " ++ msg)
Run Code Online (Sandbox Code Playgroud)

它将String解析为我想要的任何东西.如果字符串格式错误,则会抛出异常,显示无法解析的消息.

我在IO-Monad的do块中使用此函数

(a,b) <- parse msg :: IO (Int,Int)
Run Code Online (Sandbox Code Playgroud)

在另一个地方

s <- parse msg :: IO String
Run Code Online (Sandbox Code Playgroud)

现在,如果我想使异常更详细,报告哪种类型无法读取

import Data.Typeable
import Text.Read (reads)

parse :: (Read b, Typeable b) => String -> IO b
parse msg = case reads msg of …
Run Code Online (Sandbox Code Playgroud)

polymorphism haskell types return-value

6
推荐指数
1
解决办法
292
查看次数