在If语句Haskell中使用Maybe helper

时间:2014-10-21 03:32:50

标签: haskell

module Meth where


put :: (Int,Int) -> [(Int,Int)]
put (a,b) = [(a,b)]

checker :: [(Int,Int)] -> Int
checker b = snd(last(b))

swap :: [(Int,Int)] -> [(Int,Int)]
swap [(a,b)] = [(b,a)]  

如果对与配对列表中的倒数第二个元素匹配,我想将一对连接成一对配对列表。我正在使用一个Maybe类型,它正在抛出一个很长的错误。任何帮助将不胜感激

qwerty :: (Int,Int)-> [(Int,Int)] -> Maybe [(Int,Int)]
qwerty (a,c) b = if snd(last b) == fst(head (put (a,c))) then Just b ++ put((a,c)) else 
                                                                         if snd(last b) ==  snd(head (put (a,c))) then Just b ++ swap (put(a,c)) else Nothing

1 个答案:

答案 0 :(得分:0)

Just b ++ put((a,c))被解析为(Just b) ++ put((a,c)),无效。您似乎应该写Just ( b ++ put((a,c)) )代替Just ( b ++ swap (put(a,c)) )