When I run this code in the REPL, it throws Error: syntax error: inserting DOT. I would like to know what that error message means.
I have since fixed the code and still want to know the meaning of that message for future reference.
part_dir is function that returns a custom datatype direction with possible patterns Left and Right.
fun same (fs)=
case fs of
(f1::f2::fs') => case (part_dir(f1),part_dir(f2)) of
(dir1=dir2) => same (f2::fs')
| _ => false
| _ => true
“syntax error: inserting DOT” means that there’s an unexpected token at the position it’s complaining about and that a dot would be legal at that position. However that does not mean that a dot would be the only thing allowed in that position or that replacing the token with a dot would fix your error.
For the most part the error message is useless beyond telling you that there’s a syntax error at that position. You should probably just ignore the “inserting DOT” part as it generally doesn’t lead you in the right direction. Just look at the line and column it’s complaining about and try to find what the syntax error is there.
In your case the problem is that
dir1=dir2is not a legal pattern. A legal pattern would be the constructor of a datatype with patterns for each of its argument, a variable name,_or a constant or a tuple of patterns. There is no pattern to say “a tuple that contains two elements that are equal”. For that you need the pattern(dir1, dir2)and then the conditiondir1=dir2in anif.In your case you don’t even need an
ifthough. You can just write: