7
votes

I've been stuck on this for a few days now... Sorry for such a question, but I'm just a beginner in F# itself. As there are a lot of discussions about type providers I decided to build one and write a paper about it. When I began I had no idea what type provider is. Now I have some idea and I have built a simple CSV type provider, but I lack arguments in the evaluation about, how much time and work would it take to make something like this in other languages. So far I haven't found any clue about it, just that type provider is a feature in F# 3.0. Can anyone help me out, please?

2
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. - aaron
There are similar facilities in many languages. For example, macros in Lisp and TemplateHaskell extension of GHC. Generally such things fall under the concept of "metaprogramming". Use that to google. - Fyodor Soikin
Thanks, @FyodorSoikin! I will try to search for it right away. - janix89
Keep in mind that metaprogramming facilities in other languages won't be exactly the same as F# type providers. Some will be more flexible, some less so; some more general, some less. As such, it probably won't be a fair comparison to implement in other languages something that you could do with type providers. - Fyodor Soikin
Well, the idea is, that I have to compare it with something even though it might not be a fair comparison. Just to show that I haven't stopped only by implementing type provider which is part of F#. It will be a good way to show that I found some similar approaches and can explain the main concept. This was really helpful @FyodorSoikin, as I didn't know even how to search for something relevant. Although I came across the macros in Lisp, but I wasn't sure about it. - janix89

2 Answers

13
votes

As far as I know, the only other language that directly implements type providers is Idris. See the Idris documentation on type providers. There are some examples, including SQL type provider in David Christiansen's GitHub repo. As a dependently typed language, type providers have quite a different look than in F# - they are basically computations in the IO monad that are invoked using the %provide command - so they are a bit more uniform with the rest of the language compared to the F# design.

There are other language features that are related to type providers.

  • This includes various templating systems (such as Template Haskell and camplp4 for OCaml). These lack some of the type provider features (they actually generate code, so you cannot provide "infinite size" types and they are not as integrated with the tooling).

  • There are lots of code generation tools for languages such as Java and C# (LINQ to SQL uses code generation and various UI frameworks do too), but again, this lacks the language integration and can only support types that are relatively small.

  • Another relevant thing is meta-programming such as multi-stage programming, but as far as I can say, this is mostly just academic and there is no solid language implementing this.

It is difficult to say which of these are close to type providers. For me, the essential feature of type providers is the quick feedback I get as a developer when using them (and for some, this means updating schema on the fly during development) - and that's something that code generation tools generally do not do. The other - being able to provide infinite number of types lazily is useful for some type providers, but not for all - so e.g. JSON, XML or CSV could be reasonably handled by a code generation tool.

6
votes

Java has something nearly identical to type providers via the new project, Manifold.

Instead of Type Provider, Manifold calls it Type Manifold. Although Manifold provides Java with several other features, the Type Manifold API is the foundation upon which all the others are built. Similar to F#, with Manifold Java has type-safe access to virtually any kind of structured data from SQL to CSV to JSON to Javascript... provided there is a Type Manifold implemented. IntelliJ IDEA provides comprehensive support for Manifold via the Manifold Plugin.

Cheers.