Tuesday, January 25, 2011

Funny crash of F# type inference with visual studio 2010

(warning this posting is buggy because the lesser and greater chars are taken as html comands, I'll fix it at some point)

I had a type, something like:
type Type =
| A of X
| B of Y
| C of Z


And I needed to convert it to
type Type'<'X> =
| A of 'X
| B of Y
| C of Z

type Type = Type'<...>


I had added a phantom type to X so I had

type Type = Type'> >


But when typing, I would enter X <> before finishing with the 'Tag' part (because X really has more arguments) and as a result create direct a type recursion in the Type arguments... Bang, Visual Studio goes down. It took me three crashes to understand that I needed to type the the word so as never to temporarily have the word "Type". For example, start with Tag and then add the Type in front.

Having said this, type inference sometimes need to delay unification, such as with parametrized types. In these cases it is hard to detect loops and that may well be why VS crashes.

No comments: