модуль «main:Main» определен в нескольких файлах, но это один и тот же файл
Я начинаю новый проект стека с
stack new demo
и определить второй файл
Other.hs
в папке приложений. Нет никаких зависимостей, просто:
module Other where
main :: IO ()
main = print 4
И в
package.yaml
под
executables
я добавить
other-exe:
main: Other.hs
source-dirs: app
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- debug-multiple-files
Теперь, когда я это делаю, я получаю:
<no location info>: error:
output was redirected with -o, but no output will be generated
because there is no Main module.
Поэтому я добавляю
-main-is
к ghc-параметрам:
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
- -main-is Other
В настоящее время
stack build
работает, но на
stack-ghci
, после выбора одного из исполняемых файлов я получаю:
<no location info>: error:
module ‘main:Main’ is defined in multiple files: /home/.../demo/app/Main.hs
/home/.../demo/app/Main.hs
Failed, no modules loaded.
1 ответ
Как указано здесь: /questions/51875472/sozdanie-neskolkih-ispolnyaemyih-fajlov-v-proekte-haskell-stack-po-umolchaniyu/51875479#51875479 добавление
other-modules: []
к каждому исполняемому блоку помогает. Таким образом, последний блок будет таким:
other-exe:
main: Other.hs
other-modules: []
source-dirs: app
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
- -main-is Other
dependencies:
- demo