2016-06-10 131 views
-7

我應該爲Haskell腳本使用什麼擴展? 我試圖研究它,但從來沒有得到答案,所以請幫助我。 我對函數式編程語言非常感興趣,所有我需要測試我的程序都解決了這個問題。Haskell的擴展是什麼?

+0

燦你寫得更清楚些? 'Haskell腳本'是什麼意思。像一種腳本語言? – pdexter

+2

嘗試'* .hs *'。進一步的研究,你好,請嘗試http://learnyouahaskell.com/。 – maxik

+0

我很高興地看到您似乎對Haskell感興趣,但是請您自己做一些基礎研究https://en.wikipedia.org/wiki/Haskell_(programming_language) – reto

回答

8

兩個常見的擴展名是.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] 

要能夠通過乳膠被加工生成 好看的文檔文件中嵌入代碼,代碼可以代替出現在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]