哈斯克尔的扩展是什么



我应该为Haskell文件使用什么扩展名?

两个常见的扩展是.hs.lhs。区别在于编译器处理注释的方式。在.hs文件中,注释以--开头或以{-/-}对括起来。

{- This is a multiline comment
   about my factorial function
 -}
-- It's simple using builtins
factorial n = product [1..n]

.lhs 文件中,每一行都被视为一个注释,除非它被显式标记为代码。您可以使用两种不同的样式,尽管您只能在单个文件中使用一个。首先,您可以标记代码行,以 > 开头:

In this file, we will implement factorial.
> factorial :: (Enum a, Num a) => a -> a
> factorial n = product [1..n]

将代码嵌入到可由 LaTeX 处理以生成的文件中漂亮的文档,代码可以出现在code块中:

In this file, we will implement factorial.
begin{code}
factorial :: (Enum a, Num a) => a -> a
factorial n = product [1..n]
end{code}

两者都等效于以下.hs文件:

-- In this file, we will implement factorial
factorial :: (Enum a, Num a) => a -> a
factorial n = product [1..n]

相关内容

最新更新