you can try using try\catch, exceptions and printing to find where the problem is at.
in case the exception is something you have raised, you can try to replace it with a costume exception to get the various details.
exception Yourexception of string;;
raise (Yourexception "the problem is here") ;;
if the problem is an OS exception, such as stack overflow, you can try placing prints all over the place, and slowly pinpoint the exact location
print_string( "1\n");
and when all else fail, use try and catch to slowly pinpoint the location (you can google the exception to help pinpoint the cause. for example finding that list raise the exception or something)
try (-your code-)
with exception -> (- print or handle or whatever - );;
these steps help with most of the languages, so its nice to remember them