如何在 Haskell 中编写排除某个输入参数的案例

0 parameters haskell functional-programming tuples

在 Haskell 中我怎么写:

function :: (Int,Int) ....
function Not(0,0) otherparameters = []
Run Code Online (Sandbox Code Playgroud)

即我有一个函数,除了第一个参数是元组 (0,0) 之外,我想为每种情况返回一个空列表

在 Haskell 中怎么可能做到这一点?

我尝试过函数(不是(0,0))但出现以下错误

Parse error in pattern: not
Run Code Online (Sandbox Code Playgroud)

非常感谢

Ber*_*rgi 8

首先写出异常模式:

function :: (Int,Int) ....
function (0,0) otherParameters = exceptionalResult
function _     _               = [] -- empty list in every other case
Run Code Online (Sandbox Code Playgroud)

  • 如果该函数根本不应该为“(0, 0)”定义,则显式返回“未定义”。 (2认同)