News for hackers. Stuff that matters.
Re:The Early History of F# [pdf] by adgasf on Friday January 11, 2019 @10:49AM (#18884297)
We are currently rewriting Buckaroo in F# (https://github.com/LoopPerfect/buckaroo/tree/buckaroo-redux ); previous versions were in modern Java. The productivity gains are tremendous... FParsec, async, asyncSeq, records, match expressions are all a huge leap over what most OOP languages offer. Deployments are also much easier thanks to Core RT.

F# feels like a secret weapon.

Re:The Early History of F# [pdf] by Verdex on Friday January 11, 2019 @01:24PM (#18885580)
I think the reason why is two fold.

1) The type system is focused on mathematical types as opposed to compiler tags. Mathematical types are about ensuring that a function will not fail. Compiler tags are about ensuring that you generate the correct asm op codes. Mathematical type systems allow you to have an easier time knowing the code works.

2) Algebraic data types provide both an AND component and an OR component. That is, you can do type X = A of int * int * int; AND you can do type X = A of int | B of char;. C# style languages provide you with the AND component (class A { public int B => ...; public int C => ...; }). However, they don't provide the OR component. You can create it by constructing weird type hierarchies, but this isn't idiomatic AND it also isn't closed. With an algebraic data type you can know that all of the cases are handled in a match. This isn't something you can ensure in C# (at least not naturally or easily).

Ultimately, I don't think functional programming provides anything that has to be better than object oriented programming. It's just that there are two facilities that tend to go with functional programming that allows a better way to model the problems that we encounter.

Re:The Early History of F# [pdf] by willtim on Friday January 11, 2019 @03:17PM (#18886548)
Missing from your list is arguably the most important difference: programming with mathematical (immutable) values. This allows one to build very high-level abstractions and easily reason about correctness. OOP languages simply were not designed for this style of programming.

There are also many other significant differences. I estimate I am about ten times more productive in Haskell than Java.

Re:The Early History of F# [pdf] by Verdex on Monday January 14, 2019 @12:48PM (#18904776)
I don't think mutability is problematic. The problem with mutability is that you can create hidden communication channels between different sections of your code and it can be very difficult to determine what is actually going on without carefully analyzing the entire code base at compile time and at run time for every possible input.

So if you only have mutability inside of a function and it cannot escape, then you have no problems. Or if you have a way to prevent it from crossing module boundaries.

Rust for example, gives you some pretty good tools for controlling mutability and for tracking it. I think this is actually superior to a fully immutable system as with full immutability you end up with other weird problems (like needing monads and monad transformers to do things that would otherwise be simple).

Re:The Early History of F# [pdf] by willtim on Monday January 14, 2019 @01:44PM (#18905261)
Sure, there's nothing wrong with pure functions that encapsulate mutation, even Haskell supports this, but this isn't how OOP typically works. OOP developers actually use mutation to model the real world, for example a bank balance! Many of their APIs and libraries are designed around mutation, even the default containers. Java got String right though (apart from the UTF16 part).
Re:The Early History of F# [pdf] by Verdex on Tuesday January 15, 2019 @12:29PM (#18912938)
Strong agree on the "but this isn't how OOP typically works" part.

I think one of the reasons that Rust doesn't have a traditional OO model is because you can't actually enforce mutability controls in that way. At the very least, when I tried to think of how I would find a way to enforce mutable and immutable data using java / c# style OO, I couldn't think of a way that wasn't kind of crazy or hard to use. On the other hand, structs with traits is actually pretty easy to enforce immutable data (hey, this requires a mutable borrow and what you have is an immutable borrow, so compile error).

Re:The Early History of F# [pdf] by Kip9000 on Friday January 11, 2019 @11:21AM (#18884530)
C++ package manager written in F#. This should be the tagline :P
Re:The Early History of F# [pdf] by adgasf on Friday January 11, 2019 @11:38AM (#18884661)
Haha indeed!

My position is this: different programming languages have different strengths and weaknesses. C++ is crazy fast, but it lacks many high-level features (most notably do-notation). Efficiency and performance are its niche. Conversely, F# (or any ML) is very good at expressing complex control flow, but performance is a secondary concern.

Package management is an IO-bound SAT problem, so we are using the best tools for the job.

Re:The Early History of F# [pdf] by ernst_klim on Friday January 11, 2019 @01:14PM (#18885490)
ML could be as fast as C++ and even have manual memory management. Take a look at mlton [1] and manual memory management [2]. Most ml compilers just value compile time more.

[1] http://mlton.org/Performance

[2] http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.75....

Re:The Early History of F# [pdf] by e12e on Friday January 11, 2019 @01:32PM (#18885639)
Maybe the world needs a language that is like clasp is to lisp and c++, but for c++ and ml?

Curious about your deployment happiness - are you bundling the runtime with your program? Last I checked, such a bundle was large (compared to a static c++ binary), and didn't have a nice single/few file(s) "container"?

Re:The Early History of F# [pdf] by adgasf on Friday January 11, 2019 @02:01PM (#18885914)
PureScript has a C++ back-end, which is an interesting prospect: https://github.com/andyarvanitis/purescript-native

Our development process is very pleasant. We use VS Code, .NET Core and Ionide as an IDE. I find an IDE essential for languages with global type-inference.

For bundling, we use Core RT to create a self-contained application. This is then bundled using Warp (https://github.com/dgiagio/warp) to generate a single binary.

The script is here https://github.com/LoopPerfect/buckaroo/blob/866ae97ffc82ab8...

The final binary size is quite reasonable:

- Linux 66.1 mb

- macOS 63.9 mb

- Windows 35.4 mb

I haven't investigated why Windows is so much smaller!

Re:The Early History of F# [pdf] by e12e on Friday January 11, 2019 @03:26PM (#18886615)
Thank you. If I read that correctly, the last line runs your artifact - is that for CI or something? (I'd expect the purpose was to just create the artifact?)

Ed: then again, your artifact is a build tool - does that build distribution packages?

Re:The Early History of F# [pdf] by adgasf on Friday January 11, 2019 @06:37PM (#18888272)
Yes, the last line is for CI. It just runs the tool as a simple check that it built correctly. Cross-compilation does not work with Core RT anyway, so we can assume that you are always building for the host platform.
Re:The Early History of F# [pdf] by e12e on Saturday January 12, 2019 @11:00AM (#18891713)
> Cross-compilation does not work with Core RT

Huh? I was sure I tested that after an announcement in... November? But it's supposed to have been supported a while longer? Eg: https://www.hanselman.com/blog/SelfcontainedNETCoreApplicati...

Perhaps a warp limitation?

Re:The Early History of F# [pdf] by adgasf on Saturday January 12, 2019 @04:05PM (#18893282)
I tried Linux host compiling to Windows and it did not work. Perhaps I need to update.
Re:The Early History of F# [pdf] by e12e on Saturday January 12, 2019 @05:15PM (#18893579)
I remember I had a big fight with dot.net a year or two back, and gave up - but last time I checked the only thing I found missing was a bundler (like warp). And somewhat inconsistent/unclear documentation on how to make a stand alone build. But I did eventually manage to build "Hello, world!" on Linux and run it on windows as a proof of concept.
Re:The Early History of F# [pdf] by dmead on Friday January 11, 2019 @10:58AM (#18884361)
I want to ask an annoying question.

Why F# and not haskell?

Re:The Early History of F# [pdf] by BeetleB on Friday January 11, 2019 @11:53AM (#18884780)
Not OP, but some reasons usually thrown around:

F# has the power of .NET and its libraries behind it.

Haskell's insistence on purity and laziness does increase the time it takes to design things well. F# makes it easier to violate purity in controlled ways, and is not lazy be default.

People who've used both say it's a lot easier to get lost in abstractions with Haskell, and there doesn't appear to be a clear "stopping" point. A common statement by people who move from Haskell to OCaml/F# is "I spent N years on Haskell but didn't produce much. In 6 months of (OCaml|F#) I've produced more than in those N years with Haskell."

The bottom line: The .NET libraries and slight relaxing of purity/laziness allows for more productivity.

(I'm not an expert on either - just repeating what you normally find in the threads).

Re:The Early History of F# [pdf] by adgasf on Friday January 11, 2019 @11:05AM (#18884405)
The main reason was that team had more experience with F#. I think it is also more approachable than Haskell for OOP devs (C# to F# comparisons are quite common on the internet). I'm sure Haskell would also have been an excellent choice though :)
Re:The Early History of F# [pdf] by nikofeyn on Friday January 11, 2019 @05:38PM (#18887876)
f# is a multi-paradigm language. it allows you choose what paradigm fits the problem best and allows you to easily mix paradigms, and it does so in a clean way. haskell does not have this flexibility. this is f#'s power.
Re:The Early History of F# [pdf] by lmm on Friday January 11, 2019 @11:41AM (#18884689)
Why not Scala? That's a very similar language to F#, and JVM interop would let you do a gradual migration.
Re:The Early History of F# [pdf] by saberience on Friday January 11, 2019 @11:49AM (#18884757)
The scala toolset is incredibly crap though. Ask the engineers on my team about the huge pains of transitioning to using IntelliJ from Visual Studio, or the joy of trying to make SBT do what we want it to do, then trying to use Maven instead.

Any new engineer we get started with Scala has to spend about a week making their local setup work. It's a total pain in the arse.

Re:The Early History of F# [pdf] by lmm on Monday January 14, 2019 @09:29AM (#18903153)
SBT is awful (so ignore it); Maven is wonderful. Visual Studio is very good, but grandparent said their code was previously in Java, in which case their team will already be used to IntelliJ or Eclipse, and it's F# that would involve making a transition.
Re:The Early History of F# [pdf] by adgasf on Friday January 11, 2019 @11:43AM (#18884702)
We wanted to make significant changes, so a gradual migration would not have been possible regardless of language. Regarding Scala vs F#, I do not know enough Scala to comment. Perhaps someone else can weigh in?
Re:The Early History of F# [pdf] by bunderbunder on Friday January 11, 2019 @01:31PM (#18885638)
I've spent a fair bit of time with both. Personally, I don't find the two to be all that comparable -- they're fairly distant cousins.

F# tends to stick much more closely to its ML roots, and fairly scrupulously retains a more ML flavor except when necessary to achieve good interop with the .NET ecosystem.

Scala, on the other hand feels less to me like a dialect of ML and more like an ML-flavored object-oriented language, because it mixes in OOP-style features much more freely. Its algebraic data types, for example, are explicitly implemented as class clusters. A lot of people like this, others see it as an anti-feature. Where you fall probably depends on how you feel about the relative merits of OOP and FP.

It's also, for better or worse, less concerned with maintaining good interop with the rest of the ecosystem. Consuming F# modules from C# isn't always pretty, but it's always possible. There will be C#-friendly wrappers, but creating them is a matter of aesthetics rather than necessity. Consuming Scala modules from Java, though, frequently requires creating wrapper libraries. On the upside, this does mean that Scala gets to have things like typeclasses, which the F# team has kept out of the language due to concern about how they would impact interoperability with the rest of .NET.

Last but not least: F# has type providers. Scala has implicits. F# has quotations. Scala has more stuff that's also called implicits.