Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我无法在Haskell中运行模块_Haskell - Fatal编程技术网

我无法在Haskell中运行模块

我无法在Haskell中运行模块,haskell,Haskell,前奏曲>:重新加载 dosya.hs:32:30:错误:输入“where”时分析错误 | 32 |模块转置转置,其中|^^^^^ [1/1]编译主dosya.hs,解释 失败,未加载模块。Data.List中已经有转置函数,但看起来您不想使用它。相反,您试图定义一个转置模块,该模块导出您自己的转置函数,您可以将其导入其他模块,对吗 如果是这样,您的尝试会出现几个问题: Module Transpose (transpose) where import Data.List transpose :

前奏曲>:重新加载

dosya.hs:32:30:错误:输入“where”时分析错误 | 32 |模块转置转置,其中|^^^^^ [1/1]编译主dosya.hs,解释 失败,未加载模块。

Data.List中已经有转置函数,但看起来您不想使用它。相反,您试图定义一个转置模块,该模块导出您自己的转置函数,您可以将其导入其他模块,对吗

如果是这样,您的尝试会出现几个问题:

Module Transpose (transpose) where
import Data.List 
transpose :: [[a]] -> [[a]]
map sum $ transpose [[0,3,5,9],[10,0,0,9],[8,5,1,1]]
您可能需要的是包含以下内容的Transpose.hs文件:

-- "module" must be lowercase
Module Transpose (transpose) where

-- this import may interfere with your own definition of `transpose`
import Data.List 

-- this type signature has no associated definition
transpose :: [[a]] -> [[a]]

-- you can't include this code in the middle of the module;
-- it needs to be part of a function definition
map sum $ transpose [[0,3,5,9],[10,0,0,9],[8,5,1,1]]
然后是另一个文件Test.hs,该文件在主函数中导入并测试它:

-- contents of Transpose.hs
module Transpose (transpose) where

import Data.List hiding (transpose) -- don't use Data.List definition

transpose :: [[a]] -> [[a]]
transpose = error "to be implemented"
有了这两个文件,您应该能够从GHCi加载测试并运行main:

-- contents of Test.hs
import Transpose

main = do
    print $ map sum $ transpose [[0,3,5,9],[10,0,0,0],[8,5,1,1]]
或者编译并运行它:

λ> :l Test
[2 of 2] Compiling Main             ( Test.hs, interpreted ) [flags changed]
Ok, modules loaded: Main, Transpose (/scratch/buhr/stack/global-project/.stack-work/odir/Transpose.o).
Collecting type info for 1 module(s) ... 
λ> main
*** Exception: to be implemented
CallStack (from HasCallStack):
  error, called at ./Transpose.hs:7:13 in main:Transpose

模块是小写的。但是转置签名没有多大意义,因为它是通过Data.List导入的,在这里看起来好像你想自己定义它。最后一行也是错误的:你不能简单地在一个.hs文件中写这样的表达式,你需要写一个定义,比如result=map sum$。。。。然后让GHCi评估结果。我试着用小写字母。我自己如何定义转置或结果我不确定最初的意图是什么,但我怀疑签名可能是试图导入或重新导出函数的一部分,就像某些其他语言中的声明一样。在这种情况下,为了简单地使用标准转置,可以省略签名转置::…并且可以使用import Data.List转置或原始import Data.List导入转置。
$ ghc Test.hs
[1 of 2] Compiling Transpose        ( Transpose.hs, Transpose.o )
[2 of 2] Compiling Main             ( Test.hs, Test.o )
Linking Test ...
$ ./Test
Test: to be implemented
CallStack (from HasCallStack):
  error, called at ./Transpose.hs:7:13 in main:Transpose