9 ms·
F# Data Type Providers in .Net Core (2018)
- phillipcarter 7y agoNote: article is from 2018 - since then, the FSharp.Data package has long moved out of preview and many other Type Providers work well on .NET Core.
- kroltan 7y agoYou're right, sorry for breaking the format. Hopefully a mod can fix it since I'm not able to edit the post anymore. I picked that article just because it is a very concise explanation, a bit more proper for sharing, than the official documentation, which currently requires a bit of hyperlink-following and generally nonzero familiarity with the language.
- EdwardDiego 7y agoAh, F#, when I was desperately trying to get skills in .NET (lots of .NET in my town, and I don't have a degree) I encountered F# and lost my enthusiasm for C#. Which is doubly ironic now that I work for a JVM shop. I still have a lot of love for it though. Especially things like measure types.
- mc3 7y agoJVM has a lot of functional languages. As well as the usual Clojure, Scala, etc. I think it has some Haskell-like ones.
- desert_boi 7y agoIs there an ML on the JVM? The best part of F# is it felt like a simpler version of Scala, even without things like higher kinded types that are present in OCaml.
- snuxoll 7y agoFrege is a Haskell inspired language on the JVM, about as close as I’ve found.
- tombert 7y agoIt’s not exactly ML, but there is a pretty-ok port of Haskell to the JVM called Eta [0]. [0] https://eta-lang.org/ https://eta-lang.org/
- yen223 7y agoIf you squint very (very) hard, Kotlin can fill that role. You've got algebraic data types via sealed classes, a weaker form of pattern matching via `when` expressions, and decent facilities for higher-order functions.
- soulnothing 7y agoI was going to comment the same thing. I moved from F# to kotlin and have about 80% of what I want / used from F#. With more tools eco system that makes management happy. Arrow adds to that, with it's library and compiler additions. I have also been building type providers in Kotlin. Where a gradle plugin scans a file / schema then generates types and DSLs off of it. It's a pragmatic functional language. The biggest catch to me. Is there are very few places using Kotlin in a fully functional style. On the back end more often than not you'll find Spring. Which undoes a lot of these features / patterns.
- apta 7y agoIncidentally, Java is getting pattern matching that is more capable than Kotlin's (and probably on par with Scala's).
- zelly 7y agoNah there isn't, I looked. There's Scala, but I don't have 5 years lying around to get up to speed on it.
- mycall 7y agoCould F# be ported to JVM?
- juststeve 7y agoJVM has already got clojure, scala and kotlin.
- pjmlp 7y agoNot until JVM supports value types, low level pointer manipulation and reiffed generics.
- zelly 7y ago2 out of 3 of those are coming in Valhalla. You don't need pointers.
- pjmlp 7y agoIf you want to support F# without performance degradation emulating features, I am not so certain.
- adgasf 7y agoIn addition to that, the .NET runtime supports tail calls but the JVM does not, IIRC.
- pjmlp 7y agoYes, JVM still has it under "some day it would be nice". Actually this is one of the bytecodes that .NET Native doesn't handle, if I am not mistaken.
- phillipcarter 7y agoYes, but it wouldn't be F#. F# is so deeply tied to .NET semantics that you'd have a very different language, even if the syntax looked the same.
- tincholio 7y ago> I think it has some Haskell-like ones. Eta might be what you're referring to: https://eta-lang.org/ https://eta-lang.org/ (there's also Frege, but it's less haskell-y)
- platz 7y agoIs there is a moratorium on adding IL-compatible features to F# ? If so, is it keeping pace with the additions to C# ? If not, what work is being done?
- jolux 7y agoWhat’s C# got recently that doesn’t already exist in F#?
- platz 7y agowell C# 8.0 introduced async streams, for example
- dgudkov 7y agoThe async model in F# is entirely different from C#. Not sure if an equivalent of C# async streams would make sense in it.
- adgasf 7y agoF# allows you to implement such features as libraries using computation expressions.
- louthy 7y agoSo does C# with LINQ [1]. I guess C# language development tends to lean more on concrete syntax than libraries, which is a shame, but it is possible. It's also a shame LINQ can't be extended like computation expressions. [1] https://github.com/louthy/language-ext/blob/master/LanguageExt.Core/DataTypes/Task/Task.Extensions.cs https://github.com/louthy/language-ext/blob/master/LanguageE...
- chusk3 7y agoYes, and the F# library for asynchronous sequence processing had support added for them shortly thereafter (https://fsprojects.github.io/FSharp.Control.AsyncSeq/library/AsyncSeq.html https://fsprojects.github.io/FSharp.Control.AsyncSeq/library...)
- blunte 7y agoAm I missing something? This appears to be just outsourcing the record schema definition to a sample object in another file. You still have to keep that sample updated to handle new runtime data.
- rsstack 7y agoThat other file can be an online API spec, a database instance, etc. Anything that can be accessed programmatically.
- whb07 7y agoIt keeps a structure and defines the types for you to some extent. But obviously if there are breaking changes just like with anything else....things break.
- kroltan 7y agoYes, but it is comparatively easier getting say, the result of an API's GET and pasting into a file as a sample, than manually tweaking types. At least when you're starting out or if it's a small F# program. You could even use the actual network path, but that's a bit... wilder in terms of maintenance/reproducibility. Plus, since you can have arbitrary providers, such as a provider that connects to a DB and generates a type-safe "ORM" over your relational database[0] with no configuration other than pointing to the data source you're going to access at runtime. Perfect if you want to write little data transformation scripts. [0]: http://fsprojects.github.io/SQLProvider/ http://fsprojects.github.io/SQLProvider/
- DaiPlusPlus 7y agoI don’t trust an ORM to automatically reverse a database (or generate a database from POCO types) without at least some configuration - otherwise it can not determine (for example) if two tables, where one’s schema is a subset of another, are meant to be subclasses or not. But anyway - this system feels like when we use T4 to generate types as part of the build process, but more tightly integrated. I wonder if the same could be done for C# using a Roslyn add-in.
- 7y ago
- hannofcart 7y agoIs it possible for the JSONProvider to take a JSON schema as input rather than just a piece of JSON?
- coolreader18 7y agoIt looks like there is/was one, but it was abandoned by its developers: https://github.com/jet/JsonSchemaProvider https://github.com/jet/JsonSchemaProvider https://medium.com/jettech/json-schema-type-provider-why-we-built-and-abandoned-it-7b0659afad18 https://medium.com/jettech/json-schema-type-provider-why-we-...
- amluto 7y agoI wonder if Rust macros could be used to similar effect.
- afranchuk 7y agoMany languages with powerful macro systems can do the same. Still, it's cool/promising to see a .NET language capable of compile-time execution like this when they do not support macros in the same way that other languages do (but they do have plenty of reflection features and some codegen features as we see here).
- breatheoften 7y agoF# looks like a great language... A friend of mine who is a non-programmer DBA just reached out to me and asked about recommendations for learning .NET ... I've not seen anything as elegant looking as F# in the .net world before ... What do people think ... -- is F# a good language for a beginner to learn which is also sufficiently well-supported that they could find themselves building useful script-like database (MSSQL) oriented utilities as early project ...?
- muststopmyths 7y agoF# has tended to lag far behind C# in Microsoft's ecosystem. I haven't kept up with in a few years, so I don't know how far behind it still is. It is a fun language for sure. If your friend is looking into getting into .net for professional purposes, I would steer them towards C# first. That's likely to be much more useful in the long term. Especially since it can be a stepping stone to other C/C++ like languages. With F# I would bet that they hit some limitation sooner or later where something that could be easily done in C# will take more work in F#. Which could be fine if they have the time/inclination to rough it. I just would not advise F# as a resume builder.
- whb07 7y agoWhile I fully agree with F# being the step child of C#, an easy way to see what’s better is how many features get copied from which language to the other (hint: C# is like China copying tech from F#). Start with F#. Learn the basics well. Parent - Checkout https://fsharpforfunandprofit.com/ https://fsharpforfunandprofit.com/ https://docs.microsoft.com/en-us/dotnet/fsharp/introduction-to-functional-programming/ https://docs.microsoft.com/en-us/dotnet/fsharp/introduction-...
- dgudkov 7y ago>With F# I would bet that they hit some limitation sooner or later where something that could be easily done in C# will take more work in F#. From my experience of working with both C# and F# for a few years, it's more likely to be the other way around.
- zyxzevn 7y agoWith compile time execution, one can do similar things in other languages too. This video shows a very advanced and practical way of using "static introspection": Lambda World 2019 - What FP Can Learn From Static Introspection - Aditya Siram (Deech) https://www.youtube.com/watch?v=ElHi2h9Ho6M https://www.youtube.com/watch?v=ElHi2h9Ho6M What if compile time and type level programming in functional programming languages were easy, something you reach for without even thinking about it? What if you could debug type errors with a simple compile time print statement? Write highly flexible systems by being able to introspect into types at compile time? Pre-calculate large portions of your programs for great efficiency? Typed functional programming is a great and fun way to write resilient software, and as type systems have become more and more expressive in recent years, we are able to program sophisticated and useful properties at the type level for even better compile time safety. Just one problem: It is very difficult, requires advanced knowledge of the type system, the syntax is convoluted, the error messages are impenetrable, and it is nearly impossible to debug. This talk will dive into why we should steal static introspection from languages like Nim, and D, state-of-the-art imperative programming languages which can solve all these issues, make type systems much more approachable without losing any expressive power, and offer new design possibilities for functional programs.
- mycall 7y agoD is an imperative programming language? I thought it was multi-paradigm.
- scanr 7y agoI wonder if they could get the TypeScript compiler to do something similar in future.
- namelosw 7y agoYeah, that would be very helpful since there's no dependent type in a foreseeable future. For example, As a front-end heavy language, talking with other systems is quite ordinary -- a very useful case is reflecting GraphQL or SQL type without code generation.
- namelosw 7y agoF# is great, but it seems to be somehow slowed down by C#. If there's a feature that takes time to implement (eg: Type Classes from Haskell or Polymorphic Module from Ocaml), people would rather wait for CLR or IL to support the infrastructures first. As a result, there are many essential features waiting to be implemented forever.
- zelly 7y agoI'd try F# if it were hosted on JVM or better yet LLVM. Unfortunately .NET is borderline nightmare inducing so I wouldn't want to spend my free time using it. And it doesn't seem to have any better adoption than OCaml which is its supposedly outdated predecessor.
- adgasf 7y agoI think was true before .NET Core, but now the experience is quite good. It's also possible to use F# as a compile-to-js language using Fable. This code would run on Node or the browser. Then there is https://github.com/dotnet/corert https://github.com/dotnet/corert which allows ahead-of-time compilation to native code, but it is a bit more experimental.
- JaggerJo 7y agoIf your using F# want to build (cross platform) UIs take a look at https://github.com/AvaloniaCommunity/Avalonia.FuncUI https://github.com/AvaloniaCommunity/Avalonia.FuncUI