3::[4;5;2;7];;
List.length [4;5;2;7];;
[4;5;2;7]::3;;
This gives the error This expression was expected to have type int list list but here has type int
I know that it can be solved by doing : [4;5;2;7];; List.append it [3];; but is there any other way to do it?
This is a really bad question. However, The last line in your code will fail with
.. because :: concatenates an element to a list. It can only do it from the front because the list is a singly linked list. If you want to add an element at the end of the list, you’re probably using the wrong data structure. If you really want to add an element to the end of a list, you could do
Be aware that this will be really inefficient.