Haskell ghci无法加载文件

Sal*_*alo 1 haskell ghci

我是Haskell的新手并试图玩弄它.因此,我想在文件中定义一些函数,然后加载它们ghci.

我有一个文件tryout.hl,我想要ghci使用 :l tryout或加载:load tryout.hl.我得到了这两个命令target ‘tryout’ is not a module name or a source file.

我究竟做错了什么?

这是我的shell历史:

[user@pc](~/proggin/haskell)$ ls -lah
total 12K
drwxr-xr-x  2 user users 4.0K Oct 14 05:07 .
drwxr-xr-x 14 user users 4.0K Oct 13 07:51 ..
-rw-r--r--  1 user users  138 Oct 14 05:07 tryout.hl

[user@pc](~/proggin/haskell)$ cat tryout.hl 
take' :: (Num i, Ord i) => i -> [a] -> [a]  
take' n _  
    | n <= 0   = []  
take' _ []     = []  
take' n (x:xs) = x : take' (n-1) xs 

[user@pc](~/proggin/haskell)$ ghci
GHCi, version 8.4.3: http://www.haskell.org/ghc/  :? for help
Prelude> :!pwd
/home/user/proggin/haskell
Prelude> :!ls
tryout.hl
Prelude> :l tryout
target ‘tryout’ is not a module name or a source file
Prelude> :load tryout.hl
target ‘tryout.hl’ is not a module name or a source file
Run Code Online (Sandbox Code Playgroud)

Sib*_*ibi 6

Haskell源文件应该以.的扩展名结尾hs.重命名文件应该可以使它工作:

$ mv tryout.hl tryout.hs
Run Code Online (Sandbox Code Playgroud)

演示ghci:

?> :l tryout.hl
target ‘tryout.hl’ is not a module name or a source file
?> :l tryout.hs
[1 of 1] Compiling Main             ( tryout.hs, interpreted )
Ok, one module loaded.
Run Code Online (Sandbox Code Playgroud)