Is there any way to get Visual Studio debugger to display the contents of an F# seq expression?
Visual Studio knows about IEnumerable<T> objects and gives you a results view inside the watch window. If you look at one of these in the watch window you get a mess of private fields.
Some potential alternatives:
- fsi.exe does a nice job of printing sequences, but it doesn’t interact with the debugger
- Find a way to call
Seq.toArrayfrom inside the debugger. I can’t find the right syntax to invoke this from, say, the Immediate window. - Write a vizualiser. I don’t know if it’s possible to attach vizualisers to Microsoft types.
- Something else…?
Edit: Further investigation reveals that F#’s seq objects implement IEnumerable<T> just fine — they appear in the watch window as such — but for some reason the results view doesn’t appear.
However, F# (F# seq objects don’t seem to be plain IEnumerables; instead, they look to be closures coming from the functions inside the Seq module.seq objects look to be instances created using { new IEnumerable with ... }.)
One way to do this is to use the
Resultsview node which was added in Visual Studio 2008. If System.Core.dll is loaded into the process, any type which implementsIEnumerable<T>will get an extra node when expanded namedResults. Expanding that node will enumerate theIEnumerable<T>and display the results.The F# type
seqis just an alias forIEnumerable<T>so it gets the same benefit.By default you don’t see this in F# because it doesn’t make use of any types in System.Core. But you can force this DLL into the process wit the following line.