错误:'testListTuple'的等式具有不同数量的参数

时间:2017-09-23 14:27:42

标签: haskell

我正在尝试执行一个获得Expressionlist of tuples (a pair of strings)的函数,根据以下代码:

module Test where

import Data.List

type Symbol = String

data Expression = Var Symbol    -- variable
    | Lambda Symbol Expression  -- abstraction
    | App Expression Expression -- application
    deriving (Eq, Read)

expTest = Lambda "x" $ Lambda "y" $ (Var "x" `App` Var "y")

testListTuple :: Expression -> [(Symbol,Symbol)] -> [Symbol]
testListTuple (exp) ((a,b):xs) = functionTest (exp) (a) (b) : testListTuple (exp) (xs)
testListTuple _          = []


functionTest :: Expression -> Symbol -> Symbol -> Symbol
functionTest _ a b = a ++ b

runTest = testListTuple expTest [("a", "b"), ("c", "d")]

但是,会显示以下错误:

enter image description here

解决此错误后,我仍将完成functionTest

的实施

1 个答案:

答案 0 :(得分:1)

问题在于编译器所说的。 testListTuple的等式具有不同数量的参数。

第一个等式有两个:testListTuple (exp) ((a,b):xs) = ...

第二个有一个:testListTuple _ = []

正确的定义是:

testListTuple :: Expression -> [(Symbol,Symbol)] -> [Symbol]
testListTuple exp ((a,b):xs) = functionTest exp a b : testListTuple exp xs
testListTuple _ _ = []
相关问题