1

I have to create a function that receives this to work with the list parameters

check [c, (x,y,z), c, (x,y,z), ..., c, (x,y,z)]

where c is a integer and (x,y,z) a tuple

but I don't know how to implement the function

3
  • 5
    If each c is followed by a 3-tuple, why not [(c, (x, y, z)), (c, (x,y,z)), ...]? Commented Oct 27, 2020 at 17:48
  • 2
    You can't really have heterogenous lists like that. Either use a nested tuple if they come in pairs, or a discriminating union type like Either Integer YourTuple Commented Oct 27, 2020 at 17:52
  • Seeing as you can't create such a list, it seems unlikely that you have to create a function that receives them. (This looks like an XY problem.) Commented Oct 27, 2020 at 17:53

1 Answer 1

1

This is not possible. A list can only contain values of a single type. You could make a [Either Integer (Integer, Integer, Integer)], in which case your list would look like [Left c1, Right (x1, y1, z1), Left c2, Right (x2, y2, z2)], but this isn't very satisfying, will likely be difficult to work with, and can't be enforced by the type system. Remember that the more we allow the type checker to enforce, the less likely we are to run into unexpected values down the line.

Instead, you should consider bracketing the mismatched types into a list of pairs [(Integer, (Integer, Integer, Integer))], which would make the list look like [(c1, (x1, y1, z1)), (c2, (x2, y2, z2))].

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.