Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup a task for compiling haskell in vs code?

sorry for this really uninformed question but I'm trying out vs code right now and want to configure a task that's compiling the file I am working on. My folder structure and the configured task look like this:

enter image description here

The problem is, that this doesn't compile my app.hs source file but instead gives me the following ghc error: ghc: unrecognised flag: -o app app.hs. I have tested the command ghc -o app app.hs directly from the command prompt and it works just fine. So I think the error has something to do with the way vs code sends what I have written in tasks.json to the command prompt. I can't figure out what to do though. Does anybody have an idea?

like image 506
Xam Eseerts Avatar asked Jul 20 '26 06:07

Xam Eseerts


1 Answers

Thanks to @duplode and with a little playing around I now came up with the following task-setup (see picture below):

enter image description here

For answering my question only the first out of the three tasks I defined is of relevance. As you can see the trick was to change "args: ["-o app app.hs"]" to "args: ["-o", "app", "app.hs"]". Please note however that -o app is not relevant and can be omitted in this case. The -o-flag is for renaming the ghc output files. If you omit this flag ghc will name all of the output files according to the input filename. So in my case the input file app.hs leads to the output files app.exe, app.o and app.hi. Only if you want to name your output files different from your input file does it make sense to use the -o-flag.

As for the other two tasks I defined: If someone will ever read this and be interested in it, just comment or send me a message.

like image 186
Xam Eseerts Avatar answered Jul 21 '26 21:07

Xam Eseerts