1

I have this list of type ([(Double,Double)],[(Double,Double)]). example list = ([(1.0,1.0), (2.0,1.0), (1.0,1.0), (1.0,3.0)],[(1.0,4.0), (1.0,5.0), (1.0,1.0), (1.0,2.0), (1.0,3.0), (1.0,4.0), (1.0,5.0)])

How would I access all the data after the fourth tuple (1.0, 3.0). I have already tried the tail function but doesn't seem to work. Thanks.

3
  • i assume the value of the type is correct and your type declaration is not - therefore I adjusted the type Commented Apr 5, 2016 at 14:33
  • could you please elaborate what you mean by accessing? Also could you show expected input/output of such a function? Commented Apr 5, 2016 at 14:34
  • Is the problem about always accessing all data after the fourth tuple, regardless of how many tuples are in the first list of the outer tuple? Or is it about getting all the data in the second list of the outer tuple? Commented Apr 5, 2016 at 15:01

2 Answers 2

4

Well, for one, your list isn't a list, but a tuple :)

type MyData = (MyList, MyList) type MyList = [MyListElem] type MyListElem = (Double, Double) 

Now, accessing the 2nd list is simply snd.

snd :: (a,b) -> b 

So in your case:

snd :: MyData -> MyList 

Alternatively, using Lens, you can use a lens on that directly:

list ^. _2 
Sign up to request clarification or add additional context in comments.

Comments

1

It's not a list, but a tuple of lists. In fact, a tuple of lists of tuples.

To get the second part of a tuple, use the snd command:

snd ([(1.0,1.0), (2.0,1.0), (1.0,1.0), (1.0,3.0)],[(1.0,4.0), (1.0,5.0), (1.0,1.0), (1.0,2.0), (1.0,3.0), (1.0,4.0), (1.0,5.0)]) 

This yields:

[(1.0,4.0),(1.0,5.0),(1.0,1.0),(1.0,2.0),(1.0,3.0),(1.0,4.0),(1.0,5.0)] 

From here on, you can continue to get the parts of the second list using tail or the !! operator.

For completeness, the first part of a tuple can be obtained using the fst command.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.