.hs File Extension

Learn what a .hs file contains, how to open and run Haskell source code, how Poly supports it, and how it differs from related Haskell files.

File extension details for .hs

Full Support
File typeHaskell source code
MIME type
EncodingPlain text, normally UTF-8
Operating systemsWindows, macOS, Linux
Opens withVisual Studio Code, IntelliJ IDEA, GHCi, Any text editor
Poly supportYes. Poly recognizes .hs as readable Haskell source code.
Indexed by PolyYes. Poly indexes readable source for exact and semantic search.
Preview in PolyYes. Haskell source opens in Poly's code editor with syntax highlighting.
Poly agentYes. The Poly agent can read and reason about the source text.

What kind of file is a .hs?

A .hs file contains ordinary Haskell source code. It is editable text, not a compiled executable. A file commonly defines one module with declarations for functions, types, classes, and values. GHC recognizes .hs as Haskell source that should be preprocessed and compiled.1

There are no fixed magic bytes. Editors and build tools identify the language from the suffix, project context, or source syntax. Haskell source uses Unicode characters, and UTF-8 is the practical encoding for current projects.2 IANA does not register a Haskell-specific media type, although some software uses the unregistered text/x-haskell. Poly classifies .hs as readable text/plain.3

Renaming another source file to .hs does not translate it into Haskell. It only changes the filename and may cause editors or compilers to apply the wrong language rules.

How do I open a .hs on my computer?

Any text editor can open .hs files on Windows, macOS, or Linux. Visual Studio Code with Haskell Language Server, IntelliJ IDEA with a Haskell plugin, Vim, Neovim, and Emacs can add syntax highlighting, completion, navigation, and diagnostics.

Install GHC when you need to check, run, or compile the code. GHCi can load a source file interactively, while GHC can build an executable:4

ghci Main.hs
ghc Main.hs -o my-program

For a real project, follow its Cabal or Stack instructions so dependencies and compiler options match. Opening source as text does not run it. Compiling, evaluating, or running unfamiliar code can execute arbitrary behavior and download dependencies, so review it first.

Poly support for .hs

Poly opens .hs files in a code-friendly viewer with Haskell syntax highlighting, word wrap, and in-file search. It indexes readable source for exact and semantic search, so you can find a symbol by name or search for code by purpose.

The Poly agent can summarize a module, explain a type signature, and help trace likely behavior. Poly does not compile the file, evaluate expressions, resolve packages, or reproduce a language server's project state. Keep related modules, package files, tests, and documentation together when broader context matters.

History of .hs

Haskell began with a committee meeting in September 1987 that sought a common, open language for lazy functional programming. Haskell 1.0 followed in April 1990.5 The compact .hs suffix became the conventional name for ordinary Haskell source and remains the input suffix recognized by GHC.

The language later stabilized around Haskell 98 and Haskell 2010. The suffix does not declare which language edition or GHC extensions a file needs. Those details come from the source, compiler flags, and project configuration.

Haskell tooling uses several similar-looking suffixes:

ExtensionTypical role
.hsOrdinary Haskell source
.lhsLiterate Haskell source, with prose and code
.hs-bootGHC boot module used to break certain import cycles
.hiCompiler-generated binary interface, not source text
.oCompiled object code

GHC normally expects an importable module such as Data.Tree in a matching path such as Data/Tree.hs.6 Keep source and package configuration in version control, but treat .hi and .o files as reproducible build output. Use GHC, Cabal, or Stack to build the project instead of changing extensions.

Footnotes

  1. Glasgow Haskell Compiler. GHC User's Guide: Meaningful File Suffixes. Lists .hs as Haskell source code that GHC preprocesses and compiles.
  2. Haskell.org. Haskell 2010 Language Report: Lexical Structure. Defines Haskell source in terms of Unicode characters.
  3. Internet Assigned Numbers Authority. Media Types Registry. The registry has no Haskell-specific media type.
  4. Glasgow Haskell Compiler. GHC User's Guide: Using GHCi. Documents loading source files for interactive use.
  5. Hudak, Paul, John Hughes, Simon Peyton Jones, and Philip Wadler. A History of Haskell: Being Lazy with Class. Records the 1987 committee meeting and the April 1990 Haskell 1.0 report.
  6. Glasgow Haskell Compiler. GHC User's Guide: Filenames and Separate Compilation. Describes the module-to-path convention and generated interface and object files.
© Poly Corp. 2026