Haskell Cabal package - can't find Paths_ module

只谈情不闲聊 提交于 2020-12-02 07:28:12

问题


I'm working on a Haskell project (Happstack server + Blaze HTML/front-end as main libraries) and I want to add a static data directory.

Looks like you can do so with Cabal using the auto-generated Path_<package_name> module. So in my example, the package is called new-website, so that module should be called Paths_new_website.

Link to Cabal docs re: a custom package's Paths_pkgname module.

From the command line and using cabal repl, I am trying to confirm that I'll have access to the Paths_ module. However, I'm finding that the Paths_new_website module isn't being imported by Cabal when running cabal_repl.

Here's a link to some relevant code and terminal output via a gist.

Does anyone have experience with this, getting a finicky Paths_ module to load with my package? I suspect this may be a question of lexical scope between Main.hs (the primary source file) versus the context in cabal_repl...


回答1:


Paths_* modules are only generated by Cabal during builds. If you're running the package using GHCi or cabal repl then they simply won't exist and your code will fail with "Cannot find module" errors.

There's a sneaky development mode trick, though: just build your own Paths_* module and place it in your haskell-source-dir. During development, GHCi will load that module and you can adjust its exported symbols to make your development environment fly. During build, Cabal will overwrite your module with its own and take into account the final information needed to build the Paths_* module.

So in this particular case, just make a file src/Paths_stackbuilders.hs and provide it a relative path to the datadir.



来源:https://stackoverflow.com/questions/21588500/haskell-cabal-package-cant-find-paths-module

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