Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do F# 3.0 type providers use the DLR under the hood?

Do F# type providers work by using the DLR under the hood? That is to say, do they work in the way that the dynamic keyword in C# does? How is this related to expando objects?

How does codegen fit in?

like image 225
royco Avatar asked Dec 17 '22 08:12

royco


2 Answers

Type providers are plugin to the compilation process. Internally a type provider may use DLR or anything but when the compiler ask it for a type it needs to return a type that is statically resolved at compile time. Think of it like rather than a human creating a type (class in C#) you have a assembly (type provider) which the compiler can ask to create a new type at compile time.

Ex: In case of SQL type provider the type representing the tables will be generated at compile time and put in the assembly as static types.

like image 101
Ankur Avatar answered Jan 02 '23 02:01

Ankur


Type providers solve similar problem as the dynamic keyword in C# - both of them were designed to make it easier to access data that have some structure that is not described in your programming langauge and so you need to somehow infer it later.

The dynamic keyword just lets you access any member (i.e. data filed) or method at compile time and then decides how to handle the operation at runtime. If you're using it to access .NET object, then it will use DLR, but if you're accessing some other object (like JSON data) then it will perform some simple dictionary lookup.

F# type providers are quite different - they infer the structure at compile time and pass it to the F# compiler. The compiler will then check all your code. The type provider also decides how the access to a field or method should be compiled. Typically, it will either replace it with an ordinary .NET type (so it will be compiled as normal .NET invocation) or it will replace the object with some dictionary lookup. A type provider may use DLR under the cover, but I don't think it is very common case.

like image 42
Tomas Petricek Avatar answered Jan 02 '23 02:01

Tomas Petricek