好的,这一次我要说清楚,function1的工作是检查一个字符串是否出现'?'事情,他会把剩下的字符串放在一个列表中。如果不是,它将一切都存储在堆栈,我怎么能做到这一点在Haskell中的表中存储数据
function2 :: [String] -> [([Char], [Integer]->[Integer])]
function1 :: [String] -> [Integer] -> ([Integer], String)
function1 [] stack = (stack, "")
function1 (x:xs) stack
| x == "?" = function2 xs -- # map the tokens after '?' to functions
-- # and put them into dictionary for
-- # function1's later use
| x == "m" = function1 xs ((read x :: b):stack)
| x == isJust lookup = eval xs (f stack)
...
where lookup = -- # lookup(f) is the function that is mapped from the token x
如果你想让你的函数返回一个不同的类型,然后让它返回一个不同的类型。如果'function2'没有返回'b',那么你需要编写一个函数来将'function2'的输出转换为'b'类型的东西,然后将它应用到'function2'。 – jrockway 2010-07-03 05:19:30
不,不,不必,有一些方法可以绕过这个返回,就像在函数2中写一些会返回b的东西,但是函数2仍然会自己完成 – Rn2dy 2010-07-03 05:27:59
的工作,这正是Jrockway提出的。只需用'function3 x = SomeB'写一个'function3 :: a - > b',并在第一个函数中使用'function3(function2 xs)'。 – tonio 2010-07-03 06:16:17