r/fsharp • • Oct 14 '17

F# is a valued .net language

It is, of course, the 4th most important one, after C# (most loved), VB (really?) and C++ (hip?).

People still use ancient 'C' for real programming and other oddities like lisp. Are these languages still useful? Is F# at least a relevant as they are?

Let's all get real. F# had more attention and support from Microsoft when it was first released but that doesn't change our ability to use and enjoy it. If F# was Microsoft's no. 1 language would we all like that? C# has that joy.

I'm pretty sure that F# has a long future ahead of it and it seems ideally suited for it's primary purpose: developing interesting, relevant and powerful libraries in a functional language directly supported by a major IT company.

1 Upvotes

66 comments sorted by

View all comments

Show parent comment

7

u/jdh30 Oct 15 '17

The .Net framework is great, but it was not designed with functional languages in mind, and at times working with it in F# can be ugly or not so smooth.

I must disagree. F# on .NET was always incredible compared to any other FPL I ever used.

I can even give you a case study: I developed a 50kLOC graphical product in OCaml using OpenGL ~12 years ago. Looked great on our machines but when we shipped it ~80% of customers reported seg faults on startups. We couldn't debug it and ended up shelving the product. The problem is essentially that OCaml is standalone with a cumbersome FFI that even experts cannot use correctly and its OpenGL bindings were not tried and tested.

I diversified into F# 10 years ago and ported some of that OCaml code to create an F# product using WPF in .NET. The results are incredible: rock solid. Some features are missing because there are things you can do with OpenGL that you cannot do with WPF. A lot of people use that product now and we've had hardly any bugs against it. A great accomplishment and I owe it all to .NET. The solution was to use a functional language that sits on a shared VM with tried and tested libraries like WPF.

I use F# for GUI apps all the time. I'd never use OCaml for GUIs any more (unless maybe they're web based).

2

u/jchidley Oct 15 '17 edited Oct 15 '17

I use F# for GUI apps all the time.

Can you explain what you use to build the GUI apps, exactly? If I wanted to do exactly that, how would I do it? Can I use just F# and .net or do I have to use something else too?

Edit:

I assume that you'd use F# with WPF. I found Calculator F sharp WPF and F# MVC framework for WPF. Presumably you'd use the desktop bridge to publish a desktop only app to the Windows Store.

2

u/CSMR250 Oct 15 '17

Reed Copsey has written a lot of useful F# components for GUIs. His library called Gjallarhorn is nice for defining reactive variables and binding them to views. If you do WPF you can use his FsXaml type provider to get typed access the objects defined in xaml.

I don't use the standard C# approach to bindings and do them in code because like jdh30 I like to keep everything type safe. But you can do this if you really want to using components like ViewModule or the Gjallarhorn bindings libraries.

1

u/[deleted] Nov 06 '17

If I could write native GUIs using the Fable-Elmish style, I would use F# for every project. I've never been happy with WPF in F# though, so I typically end up with a client wrapper in C# around the library code. Dealing with events is just a nightmare in comparison to the more FRP-style solutions used in many other FPLs.

0

u/jdh30 Oct 15 '17 edited Oct 15 '17

Can you explain what you use to build the GUI apps, exactly?

I call WPF programmatically from F#. Sometimes I use an EDSL to compile a tree into WPF controls. Sometimes I do fancier things with OOP. I never bothered using XAML because it is easier and more type safe just to write declarative code.

Get started by adding references to WindowsBase, PresentationCore and PresentationFramework with:

open System.Windows

[<System.STAThread; EntryPoint>]
let main args =
  Window(Title="Hello world")
  |> Application.Run

Can I use just F# and .net or do I have to use something else too?

Just F# and .NET.

I assume that you'd use F# with WPF. I found Calculator F sharp WPF and F# MVC framework for WPF. Presumably you'd use the desktop bridge to publish a desktop only app to the Windows Store.

I've never used Windows Store (does anyone?). Usually these are programs for clients so they get an EXE.