While looking for a function in haskell that flattens arbitrarily deeply nested lists, i.e. a function that applies concat recursively and stops at the last iteration (with a non-nested list), I noted that this would require to have a more flexible type system because with varying list depth, the input type varies as well. Indeed, there are several stackoverflow question - such as this one - in which the responses state that "there cannot exist a function that will 'look' at different nested lists at different depths".
EDIT: Some answers provide workarounds in haskell, either for custom data types or with the help of TypeFamilies or MultiParamTypeClasses (as in the answer by Noughtmare below or the answer by 'Landei' in the post above or the answer by 'John L' in this post).
However, those Families and Classes also seem to have been introduced for the lack of / to substitute dependent types in haskell (for example, the haskell wiki states "Type families are [...] much like dependent types".
My question now is if it is true that haskell was indeed originially not made for defining such functions (that e.g. flatten lists of different depths) and, furthermore, if such problems would vanish once one moved to a language that implements dependent types? (For example Idris, Agda, Coq, ...) I do not have experience with those languages which is why I am asking.
For example, on the Idris website, it is said that "types can be passed as arguments to functions" and thus, I thought, in the case of the list flattening, one could maybe simply pass the type of the list as argument and implement the desired function in a straightforward way. Is this possible?
A follow-up question would also be: Do those Families and Classes that work around this issue in haskell provide a full implementation of dependent type theory in haskell or if not, what are important differences?