[英]Simple haskell program doesnt compile with GHCi
考慮以下是我的代碼
import Data.Char
import Data.List
-- square
square :: Int -> Int
square n = n * n
盡管這個正方形函數看起來很整潔,但是當我運行它時
ghci ./square.hs
它返回
[1 of 1] Compiling Main ( ./LabSheet1-solns.hs, interpreted )
./LabSheet1-solns.hs:5:1:
parse error on input `square'
Failed, modules loaded: none.
我的翻譯可能應該有問題。
我在OS X 10.8.1上運行
$ ghci --version
The Glorious Glasgow Haskell Compilation System, version 7.4.2
有什么線索嗎?
您的import
語句縮進一個空格。 這基本上將“一個空格”設置為文件的基本縮進級別。 由於您對square
的定義沒有縮進一個空格,因此會出現語法錯誤。
要解決此問題,可以將所有行縮進一個空格,或者最好不要縮進import
語句。
修正縮進:
import Data.Char
import Data.List
-- square
square :: Int -> Int
square n = n * n
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.