Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the extension for Haskell? [closed]

Tags:

haskell

What extension should I use for a Haskell file?

like image 984
Xyz Avatar asked Nov 28 '22 14:11

Xyz


1 Answers

Two common extensions are .hs and .lhs. The difference is in how the compiler handles comments. In a .hs file, comments begin with -- or are enclosed in {-/-} pairs.

{- This is a multiline comment
   about my factorial function
 -}

-- It's simple using builtins
factorial n = product [1..n]

In a .lhs file, every line is considered a comment, unless it is explicitly marked as code. There are two different styles you can use, although you must use only one within a single file. First, you can mark lines of code by prefix them with >:

In this file, we will implement factorial.

> factorial :: (Enum a, Num a) => a -> a
> factorial n = product [1..n]

To embed code in a file that can be processed by LaTeX to produce nice looking documentation, code can instead appear in a code block:

In this file, we will implement factorial.

\begin{code}
factorial :: (Enum a, Num a) => a -> a
factorial n = product [1..n]
\end{code}

Both are equivalent to the following .hs file:

-- In this file, we will implement factorial
factorial :: (Enum a, Num a) => a -> a
factorial n = product [1..n]
like image 108
chepner Avatar answered Dec 10 '22 13:12

chepner