3 ms·
Type providers were the biggest innovation I learned from F#. Type providers are a way to have static typing determined from an external source, like a CSV file
by chrisaycock 6y ago
Type providers were the biggest innovation I learned from F#. Type providers are a way to have static typing determined from an external source, like a CSV file or SQL database.
I ended-up using a similar trick (with different syntax) in my own language, Empirical. I needed a way to infer a Dataframe from a file while in a REPL. It wasn't until I read the MSR paper that I realized I could do it entirely in the compiler without creating separate logic for the interactive users.
https://dl.acm.org/doi/10.1145/2908080.2908115 https://dl.acm.org/doi/10.1145/2908080.2908115
- ridiculous_fish 6y agoWill you please share your insight? What are Type Providers? What is their advantage over, say, naively dumping type definitions from pre-processing a CSV file?
- tasogare 6y agohttps://docs.microsoft.com/en-us/dotnet/fsharp/tutorials/type-providers/ https://docs.microsoft.com/en-us/dotnet/fsharp/tutorials/typ... It’s not perfect though. When I tried to use them I ended up with problem so I parsed the data in more traditional way.
- chrisaycock 6y agoThe user could certainly dump a type definition, but for users who just want to point to some data in one go, the F# type provider[0] works with just: CsvProvider<"trades.csv">.Load("trades.csv") I personally didn't like having to list the file twice, so in Empirical[1] it's just: load$("trades.csv") My current version requires the dollar sign to tell the compiler that the parameter will be static (known at compile time). I'm planning on an updated version[2] that will eliminate the dollar from the function call: load("trades.csv") Basically, it means that users can just load the file like in a dynamically typed language, except that Empirical is statically typed. [0] https://fsharp.github.io/FSharp.Data/library/CsvProvider.html https://fsharp.github.io/FSharp.Data/library/CsvProvider.htm... [1] https://www.empirical-soft.com https://www.empirical-soft.com [2] https://github.com/empirical-soft/empirical-lang/issues/23 https://github.com/empirical-soft/empirical-lang/issues/23