How to open .LHS files on Mac
To open .LHS files on Mac, open the .lhs file with a plain-text/code editor (Control-click → Open With → choose a text editor).
Step-by-step instructions
- Open the .lhs file with a plain-text/code editor (Control-click → Open With → choose a text editor).
- To build/run it, use a Haskell toolchain that includes GHC; GHC supports .lhs via its literate pre-processor stage.
- If the file looks like a “document” but is unreadable, verify it is plain text (not a mislabeled binary file).
Common issues
The file opens, but the code parts look wrong
Literate Haskell relies on specific conventions to distinguish documentation from code; viewing it in a word processor or with incorrect text settings can make the code blocks hard to identify.
- Open the file in a plain-text/code editor rather than a word processor.
- If you are compiling, use GHC (it applies the literate pre-processor for .lhs) and confirm the file follows literate conventions described in the Haskell report.
Compilation fails because it is treated like normal .hs source
If the toolchain is not using a literate-aware compilation path, the documentation lines can be interpreted as code and cause errors.
- Compile with GHC using the .lhs file directly so the literate pre-processor stage is applied.
- Confirm you did not rename a .hs file to .lhs (or vice versa) without adjusting the file’s content to match literate conventions.
My system does not recognize .lhs / opens it with the wrong app
File-type associations vary by platform; some systems may not have a built-in association for Literate Haskell.
- Use “Open with…” and choose a text editor, then set it as the default for .lhs if desired.
- On Linux desktops, recognition can depend on the shared MIME database installed on the system.
Security note
.lhs files are plain text, but they can contain Haskell code that may run arbitrary actions when compiled/executed; treat untrusted .lhs files like any other source code you might run.