Reputation: 674
I have a list of tuples which looks like this in Haskell:
([],[[]],[])
And I want to perform some operations on these lists and return all possible changes of state onto them. I want to return a list of this tuple and I am not quite sure how to bind them together. When I tried cons or ++ I get some errors.
([],[[]],[]):([],[[]],[])
([],[[]],[])++([],[[]],[])
<interactive>:81:1:
Couldn't match expected type ‘[a]’
with actual type ‘([t0], [t1], [t2])’
Relevant bindings include it :: [a] (bound at <interactive>:81:1)
In the first argument of ‘(++)’, namely ‘([], [], [])’
In the expression: ([], [], []) ++ ([], [], [])
In an equation for ‘it’: it = ([], [], []) ++ ([], [], [])
Upvotes: 0
Views: 67
Reputation: 52280
your main problem here is that you have an tuple of lists instead of a list of tuples as you claimed - so of course neither :
nor ++
will work.
Maybe you want to use those operations component-wise, which can be done by something like:
map3 :: (a -> b -> c) -> (a, a, a) -> (b, b, b) -> (c, c, c)
map3 op (xs,ys,zs) (xs',ys',zs') = (xs `op` xs',ys `op` ys',zs `op` zs')
using this you get:
λ> map3 (++) ([],[[]],[]) ([],[[]],[])
([],[[],[]],[])
λ> map3 (:) ([],[[]],[]) ([],[[]],[])
([[]],[[[]],[]],[[]])
if this is not what you expected / wanted then please add an example on what you want
Upvotes: 2