小编Sau*_*ray的帖子

冗余模式匹配警告

我正在编写一段代码,该代码是一个函数,返回一个像素列表,这是我定义的一种特殊数据类型,其类型如下:

data Pixel = Pixel {
                    color :: Float,
                    elevation :: Float,
                    distance: Float,
                    visited :: Bool
                   } deriving (Show)
Run Code Online (Sandbox Code Playgroud)

我具有要通过两个文件并将它们放到一个像素列表中的功能。这些文件分别包含颜色和高程,因此我继续获取此代码输出:

insertPixels :: [String] -> [String] -> [Pixel]
insertPixels _ _ = []
insertPixels (x:xs) (y:ys) = [Pixel (read x) (read y) 99999999 False] ++ insertPixels xs ys
Run Code Online (Sandbox Code Playgroud)

当我尝试对此进行编译或将其加载到解释器中时,出现以下错误:

lab1.hs:33:1: warning: [-Woverlapping-patterns]
Pattern match is redundant
In an equation for ‘insertPixels’:
    insertPixels (x : xs) (y : ys) = ...
|
| insertPixels (x:xs) (y:ys) = [Pixel (read x) (read …
Run Code Online (Sandbox Code Playgroud)

haskell pattern-matching

2
推荐指数
1
解决办法
81
查看次数

标签 统计

haskell ×1

pattern-matching ×1