在不同的hs文件中分离函数时,堆栈空间溢出 [英] Stack space overflow when separating functions in different hs files

查看:66
本文介绍了在不同的hs文件中分离函数时,堆栈空间溢出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个巨大的haskell文件,该文件可以编译并运行,没有任何问题.我想将一些函数和类型定义放在通用hs文件的单独模块中,然后将其导入我的主模块中.虽然主程序编译时没有任何错误(它也编译了导入的模块),但是当我尝试运行它时,却出现了堆栈空间溢出的情况.

I have a huge haskell file which compiles and runs without any problem. I want to put some functions and type definitions in a separate module in a generic hs file and then import it in my main module. While the main program compiles without any error (it also compiles the imported module), I get a stack space overflow when I try to run it.

我尝试过:

ghc --make -O2 Main.hs
./Main -- stack space overflow

也:

ghc --make -O2 Main.hs Other.hs -o RunMe
./RunMe -- again, stack space overflow

是正确的编译方式还是我缺少任何东西?

Is it the right way to compile or am I missing anything?

推荐答案

您正在正确编译它.问题必须出在代码本身中.将其拆分为不同的模块可能会导致GHC应用优化的方式有所不同,从而使该问题浮出水面.

You're compiling it correctly. The problem must be in the code itself. Splitting it into different modules likely caused GHC to apply optimizations differently which caused this problem to surface.

一个可能的原因是,GHC以前能够使用严格性分析来生成在恒定堆栈空间中运行的程序.将模块一分为二然后导致GHC无法再执行相同的严格性假设,因此无法保证使功能严格是安全的.

A likely reason is that GHC was previously able to use strictness analysis to generate a program that ran in constant stack space. Splitting the module in two then caused GHC to no longer be able to make the same strictness assumptions, so it was unable to guarantee that making the function strict was safe.

解决方案很可能是添加您自己的严格性注释或使用引起该问题的函数的严格版本.

The solution will likely be to add your own strictness annotations or use a strict version of whichever function is causing this.

这篇关于在不同的hs文件中分离函数时,堆栈空间溢出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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