243 points · by adamnemecek · 6y ago · 127 comments
Elmish framework provided a nice MVU pattern for the U/I.
And the real icing on the cake was this Thoth.Elmish package which creates statically-typed proxy for your front-end to access your back-end API, more or less transparently. I was always certain that I would some day do something unorthodox causing its automated serialization/deserialization to fail in some difficult-to-troubleshoot way but no, that never happened and it all just worked transparently.
This was hands down the best automated-correctness-checking experience that I've ever had in any framework.
I really like F# as a language, but it's hard to give up the high quality tooling of VS Code + TypeScript + almost any NPM package w/ proper types.
Ended up using Typescript instead and it doesn't feel as clean.
This is my gripe exactly. If you gave me Svelte# and we'd be talking (my TS is pretty functional otherwise).
I have only done some toy projects on it so far, but am really digging it.
We’re using F# React on the front-end, Giraffe on the back-end.
DustyTables for Data Access.
It’s great - can recommend.
It’s a niche, but it exists and is growing.
If you want one and are willing to take a few compromises you’ll find one.
If you want to work in F# come up with your own OSS projects or champion it at work.
What sometimes leads to problems is F#’s record and discriminated union types.
Not sure how they are handled by EF Core.
Going back to plain SQL is just great. You know exactly what SQL gets executed. No Magic.
With DustyTables it’s also not too much boilerplate.
* Suave
* AWS
* Fable
* React
SAFR? It's great, but missing a snazzy acronym.
Saturn
Azure App Service
Fable
Elmish
Slightly off topic but it’s good to see that F# is finally getting some proper web love.
All our new code is in F#, we started off from a C# codebase, so that made the transition somewhat manageable, as new F# code can be directly called from C#, and vice versa (still took over 2 years). All new frontend apps are also being written in F# (using Fable), as of 6 months back, migrating away from TypeScript, this forces everyone into a "design your model first, and well" paradigm. We've written quite a bit of code to blur the lines between traditional backend and frontend development roles, so what we have now are:
- product engineers (who write application logic on both frontend and backend to serve business needs)
- platform & framework engineers (who write the underlying persistence/serialization/versioning/frontend-backend-sync websocket/load balancing/IDE extensions/deployment etc)
- component designers who focus on visuals
Platform/framework engineers try to encapsulate as much magic as possible into computation expressions (F#'s monads), so product engineers can focus simply on writing out business intent, with readability given very high priority. We also make ample use of quotations to do some cool tricks (like predict the future states some type can take, based on current state + available transitions).
Our code written in F# has an order of magnitude fewer bugs when it makes it to production, given the amount of thought we pour in modelling the problem domain accurately, and thanks to functional programming itself. They're also more amenable to business requirements changing, simply because they've been modelled well to start with. Nothing that can't be achieved in other languages, but with F#, this happens more naturally.
Almost everyone in our team has learnt F# on the job, and overall, everyone's experience has been extremely positive. There's a bit of difficulty in the first 2-3 months, as junior devs get introduced to functional thinking, but if you've generally being doing functional programming, this is just about learning new syntax, tooling and F#'s choice of operator naming (map/bind/pick/collect/choose/..). Typically, based on prior experience, we ask newcomers to spend two weeks to a month, solving the first 100 problems on Project Euler in F#, without using the mutable keyword, and we assign a mentor to point out best practices and review their code.
The hiring pool for F# devs is much smaller than the regular applicant pool, but if a candidate shows genuine interest in F#, they are usually 10x more likely get through our interview process. If they've discovered F#, it means they find something lacking with mainstream languages, so they're likely to have many years of experience under their belt, and they've found a way to grow. That said, we don't restrict our hiring to simply F# devs.
For more info about us, see chaldal.tech (YC/S15).
Also, I really like this post: https://fsharpforfunandprofit.com/posts/low-risk-ways-to-use...
> We also make ample use of quotations to do some cool tricks (like predict the future states some type can take, based on current state + available transitions).
let transition (state: State) (action: Action) : State option =
match (state, action) with
| (StateA, ActionA) -> Some StateB
| (StateA, ActionB) -> Some StateC
| (StateB, ActionA) -> Some StateB
| _ -> None
If you get the quoted representation of the transition function, it can be visualized as a tree data structure (like code-as-data in LISP). You can analyze that tree to understand that if current state is StateB, only ActionA can be applied on it.Couple this with another realization: "Any sufficiently complicated model class contains an ad hoc, informally specified, bug-ridden, slow implementation of half of a state machine." (not sure where I read this quote).
This means all the entity framework/ORM crap work that we do can actually be neatly represented as transforms on a F# state machine, which suddenly makes the application more powerful if you give it this structure.
We use this technique to auto-generate admin panels.
Can’t tell you where you read it, of course, but believe it originates from Braithwaite/raganwald:
You can do similar things with other Ocaml or Lispy Langs, depending on how you want to do it. All you need is a function that returns possibleTypeTransitions for givenType(type, enclosedLexeme, type.validTransitions). A gradually typed lang sitting in top of a prototype-based blob also makes this easy to do (see typescript) in-codo.
See also MacKay (RIP)'s classic book: http://www.inference.org.uk/itprnn/book.pdf
I'm really having fun experimenting with F# for my API server, but I hesitate to use it on the front end.
Trying to figure out how to map to an overloaded C# callback (maybe hidden in an *.extension doc!) has wasted hours of my time.
F# (the ml family in general) is my favorite language right now but, man, the .net APIs are rough.
Lacking the same UX I’m used to in Node, Ruby, and Elixir.
I just now dumped a 350KB JQuery.d.ts file into it, and sure enough it spit out F#, but confirming how well it works overall would take a lot longer to ascertain.
Always seemed to me like having a really robust tool for this purpose (or else, just a rich direct Fable-typing selection) would be a huge boon for the whole Fable ecosystem.
Is the only difference the ecosystem around the toolchains?
F# was heavily inspired by OCaml, it was originally intended as "What would OCaml look like running on .NET?" so the languages themselves share a lot of similarities.
ReasonML pros:
- ReasonML compilation times were much faster than Fable 2, but Fable compile times weren't bad. OCaml is ridiculously fast.
- OCaml has an interesting module system that's missing from F#.
- The toolchain feels a lot more lightweight than the whole .NET toolchain.
Fable pros: - I found interop with JS and OOP stuff much easier in Fable than in ReasonML
- Fable has a tool for converting TypeScript definitions to Fable definitions - though it hasn't always worked for me for more complex type definitions
- I prefer F#'s whitespace sensitive syntax over OCaml, but that's just personal preference
- F# type providers are pretty cool
- F# has an interactive mode, and you can write standalone scripts (eg. for devops)
- If you want to write a web backend in the same language, F# on .NET is much more mature in the web space than OCaml.Computation expressions are like do-notation and list comprehensions in one feature. Now that I have tried them, I don't want to go back to a language without!
- compare their experience with ReasonML since they both have the same OcaML pedigree
- offer any perspectives on efficiencies of various constructs? For example, do things like seq add additional complexity or are about as efficient as for loops?
- discuss the output size .. by virtue of using .net libraries versus javascript builtins?
Dismissive maintainers indeed!
Would I recommend others to throw away React or similar to use it? Maybe not, but it's mostly painless to use day-to-day.
https://news.ycombinator.com/item?id=22237578 (I wrote this exact comment about you 10 months ago on another F# + JS submission)
If this is going to be your hobby horse, why not put some effort into it beyond "lol sux"?
The one true way (his book is also very good)
Don't even get me started on the total farce that was the Fable: The Journey was. Cool concept, poor implementation.
F#’s async workflows are supported.
Not sure how this is implemented behind the covers - I guess it get’s compiled to JS promises.
Good point. I guess I meant parallelism instead.
https://stackoverflow.com/questions/1050222/what-is-the-diff...
I think it can still be archived with web workers.
But honestly, its own async model is great - arguably better than TPL for business systems. It sacrifices a little top-end performance/power and in return you get a supremely clean abstraction.
I'm sure someone must use it but it's not at all common
Update: the issue is tagged await-csharp-alignment, which is probably the relevant status.