Reputation: 61
I am trying to create a func that compares a element from a tuple list with every other List for a special datatype:
data Term = Var VarName | Comb CombName [Term]
deriving (Eq, Show)
data Subst = Subst [(VarName, Term)]
deriving Show
So I am trying to do the following:
[(VarName "Y",Comb "2" []),(VarName "Y",Var (VarName "X"))] -> Subst [(VarName "Y",Comb "2" [])]
If we have a tuple (a,b) then we wanna check every tuple from [(VarName,Term)] if there is any tuple (c,d) where a=b if yes then we wanna check if b has type Comb x [] or d has type Comb x []. After checking that we wanna delete the tuple, which second component hasnt the type Comb x []. (It isnt possible that there are to tuples who have both Comb x [] as type as second component)
My try:
test :: [(VarName,Term)] -> [(VarName,Term)]
test [] = []
test ((x,y):[]) = ((x,y):[])
test ((x,y):xs) = map (check (x,y) xs)
check (VarName,Term) -> [(VarName,Term)] -> (VarName,Term)
check (x,y) [] = [(x,y)]
check (x,y) ((a,b):xs) = if x==a && y = CombName i [] then (x,y) else ((a,b))
Can some1 please help me out, I am new with Haskell. Thanks :)
Upvotes: 0
Views: 80
Reputation: 14319
I think you are looking for nubBy :: (a -> a -> Bool) -> [a] -> [a]
. Try nubBy (on (==) fst)
.
Upvotes: 1