1

Is it possible to customize the extension that haskell files can have?

That is, to tell GHC that a file with extension .yy.xxx should be accepted as a valid haskell file, and that a file with extension .yy.lxx should be accepted as literate haskell?

Ivan Perez
  • 582
  • 2
  • 17
  • 1
    Just out of interest, why do you want to do this? Is it purely to see if this is possible, or do you have a particular application in mind? – bradrn Sep 28 '19 at 02:05
  • Anyway, now that I think about it, I thought that GHC doesn’t care what extension files have? So can’t you just do `ghc myfile.yy.xxx` and have it compile? Or do you run into an error when you try that? – bradrn Sep 28 '19 at 02:06
  • Intererestingly, `runghc` doesn't mind arbitrary extensions but `ghc` does. Guess the reason is to allow scripts to have a name without extension. – leftaroundabout Sep 28 '19 at 03:23
  • @bradm How will ghc find other modules that also have `.yy.xxx` extension? – Ivan Perez Sep 28 '19 at 21:44

1 Answers1

1

GHC has a -x option to override the meaning of file suffixes, see the user guide:

-x ⟨suffix⟩
Causes all files following this option on the command line to be processed as if they had the suffix ⟨suffix⟩. For example, to compile a Haskell module in the file M.my-hs, use ghc -c -x hs M.my-hs.

I've used this to compile .md files as .lhs (instead of storing the files directly as .lhs, which may prevent other tooling from telling the format to render from).

Li-yao Xia
  • 31,896
  • 2
  • 33
  • 56
  • Great. This (using it with md) was also my thinking. The problem, I guess, is that that module might import another module also in an .md file which would not be listed in the command line. I see that GHC supports the flags `-osuf` and `-hisuf` (http://downloads.haskell.org/~ghc/latest/docs/html/users_guide/separate_compilation.html#output-files). I wonder how complex adding -hssuf and -lhssuf would be. – Ivan Perez Sep 28 '19 at 21:41
  • Github chooses how to render files based purely on the extension. However, if the extension is `.md`, then you need to create a link to the file from an lhs for this to be found by GHC. If we could name them `.hs.md` and `.lhs.md` (or the other way around), then we might be able to get github to support literate haskell with markdown. – Ivan Perez Sep 28 '19 at 21:43