Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.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
Image Haskell数据类型错误PBMfile_Image_Haskell_Rgb_Ppm - Fatal编程技术网

Image Haskell数据类型错误PBMfile

Image Haskell数据类型错误PBMfile,image,haskell,rgb,ppm,Image,Haskell,Rgb,Ppm,我正在做作业,有一个错误 我必须做一个关于现在描述的数据类型的函数 data RGBdata= RGB Int Int Int data PBMfile= PBM Int Int [[RGBdata]] 还有他的表演功能 instance Show RGBdata where show (RGB r g b) = (show r)++" "++(show g)++" "++(show b) instance Show PBMfile where show (PBM width heigh

我正在做作业,有一个错误

我必须做一个关于现在描述的数据类型的函数

data RGBdata= RGB Int Int Int
data PBMfile= PBM Int Int [[RGBdata]]
还有他的表演功能

instance Show RGBdata where
 show (RGB r g b) = (show r)++" "++(show g)++" "++(show b)

instance Show PBMfile where
 show (PBM width height l) = "P3\n"++(show width)++" "++(show height)++"\n255\n"++(foldr (++) "" (map myshow l))

myshow [] = "\n"
myshow (h:t) = (show h)++" "++(myshow t)
以及他的加载和应用功能

cargarPBM name = readFile name >>= return . rLines . lines
rLines (_:x:_:xs)= (\[a,b]->(PBM (read a) (read b) (rLines' (read a) (concat $map words xs)))) $ words x 
rLines' _ []= []
rLines' a x= (rLine (take (a*3) x): rLines' a (drop (a*3) x))
rLine []= []
rLine (r:g:b:xs)= ((RGB (read r) (read g) (read b)):rLine xs)

aplicar funcion origen destino= cargarPBM origen >>= writeFile destino . show . funcion
例如,当我尝试执行某个函数时

negative :: PBMfile -> [Int] 
negative PBM x y z = [1,2,3]
拥抱错误

ERROR file:.\haha.hs:32 - Constructor "PBM" must have exactly 3 arguments in pattern
但是PBM x y z不是3个参数吗?我做错了什么?

你需要括号

negative :: PBMfile -> [Int] 
negative (PBM x y z) = [1,2,3]
否则,它将被解析为四个参数,指向
负数

您需要括号

negative :: PBMfile -> [Int] 
negative (PBM x y z) = [1,2,3]

否则,它将被解析为四个参数,以

函数定义
负PBM x y z
尝试与四个参数进行模式匹配,其中第一个参数是
PBM
数据构造函数。要实际匹配数据构造函数及其参数,应该对它们进行分组,即
负(PBM x y z)=…
。问题中的
show
定义就是正确操作的一个例子


为了进一步阅读,请尝试。

您的函数定义
负PBM x y z
正在尝试与4个参数进行模式匹配,其中第一个参数是
PBM
数据构造函数。要实际匹配数据构造函数及其参数,应该对它们进行分组,即
负(PBM x y z)=…
。问题中的
show
定义就是正确操作的一个例子

如需进一步阅读,请尝试