Hacker News new | past | comments | ask | show | jobs | submit login
Getting Started with Functional Programming in F# (codeopinion.com)
145 points by dcomartin on Feb 9, 2017 | hide | past | favorite | 41 comments



I've recently got back in to F#, one thing I like is the fact you can leverage the world of .NET

For instance, first thing I did was I used suave.io to expose a webservice for a digital IO module ( http://www.mccdaq.com/ ) and it amounted to around 50 ish lines of code. Runs flawlessly.

The F# community is pretty awesome as well with a good ratio between experts and people learning the language.


SuaveIO is really nice to work with. Peformance is terrible but that could be fixed. Its on my list of things to have a go at improving some time with some PRs. I think the big low hanging fruit would be switching from async await to either Hopac or TPL, which is above my pay grade but there are lrobably othwr areas that could be tweaked. I encourage perf junkies to have a go at it, as it wonderful to work with.


There's a new F# project out there to utilize ASP.NET Core, which has got Kestrel under the hood. I just discovered it and have yet to do any performance testing, but I'd imagine it's pretty in-line with C# results.

https://dusted.codes/functional-aspnet-core


That looks promising!


the Suave extension for ASP.NET Core (https://www.nuget.org/packages/Suave.AspNetCore/) is fast and you can use lots of suave specific features, with same performant kestrel as base, because suave is added as middleware.

Or there is also a new attempt (https://github.com/dustinmoris/AspNetCore.Lambda) to use api similar to suave, more integrated with asp.net core itself (security/auth/etc).


fsharp would really take off if it had a framework as attractive as phoenix.


Is phoenix actually taking off outside SV startups?

There are zero Elixir jobs on my part of the planet.

Whereas F# is on my PC thanks to a full VS install done by IT, and I can at least use it instead of Powershell.


I've thought about this too, and unfortunately it is not feasible, because of the poor/nonexistent meta programming support in F#. Phoenix uses macros for optimizing functions from templates at compile time, handling translations in a clean way, and removing a lot of boilerplate.

Source: Have spent a lot of time with F#, including writing Type Providers (which would not solve the problem).


I'm not sure what you mean by optimizing functions. I understand quoting isn't the best thing going vs true macros, but fsharp has full metaprogramming capabilities and operator overload plus custom operators produce some nice DSL's.

Anyway, I don't think to be "attractive" it needs to match Phoenix/elixir macros. Nice frameworks can be made in fsharp, and its type system and tooling blows type specs and dialyzer out of the water.

Really it needs to be:

* (x-platform && easy to use) which is why I'm so keen for the official 4.1 fsharp release. The ecosystem around fsharp and dotnet core needs all the sharp edges ground down.

* Smooth OOTB experience

* Community momentum

* Excellent plug/middleware solution(building on top of asp.net core might be the right approach)

Then just let fsharp shine on its own merits.


I'm currently learning F#, and liked everything so far, in particular that you can learn both functional style as well as interaction with existing .net apis, which allows you to build typical use-cases faster (as you would know them from imperative/oo languages, like building a small crawler). I wish there was a good ML-style language for the JVM.

VS Code has good integration, check out the Ionide plugin.

For a language introduction, this wikibook is quite ok: https://en.wikibooks.org/wiki/F_Sharp_Programming


> I wish there was a good ML-style language for the JVM.

github.com/Frege and eta-lang.org may be tried out


I had looked at Frege, but it doesn't seem to have the same traction as other functional languages.

Counting on github returns about 10k for each F# and Ocaml, about 60k for Haskell, and 100k for Scala, but about < 200 for Frege.


Yeah compared to .NET there's nothing ML-ish in the F# ballpark (in terms of push/community/basic corporate support = "traction") for the JVM afaik.


True in the sense that Scala has a magnitude higher number of repos, commercial adoption, libraries, than F# (while being much closer to ML than F# in a few important was).


Whoops, my bad, the only faint idea about ML I do have is as the "MotherLode" from what I know of modern-day F# / Haskell --- never looked at Scala so far

That then should be the actual answer to OP's question


> I wish there was a good ML-style language for the JVM.

Scala?


This! Don't be fooled by the prevalence of Haskell-like libraries and patterns in the Scala community (or a vocal subset). Those are absolutely useful but you're free to use them or not, and if you want to just write ML style functional code then Scala is great for that too.

There is actually a really interesting (to me) discussion going on about where Scala sits on the Intersection of Java,ML & Haskell going on in the r/Scala subreddit at the moment:

https://www.reddit.com/r/scala/comments/5sv1w5/the_divergenc...


So, I just started learning Haskell and I learned a bit of Standard ML in the past.

I was/am expecting Haskell to be broadly similar to ML - what's the main way the two languages differ?

edit: never mind, from the reddit discussion you linked:

> while these languages are undoubtedly strongly typed, they are not referentially transparent by default, and actually embrace some levels of imperative programming.

Good read, thanks!


ML?



Ok, yeah, influenced. Javascript could also be called a LISP with C-Syntax, but that wouldn't make it a LISP. But I get what you mean.


You should compare the actual syntax and constructs. I agree that JS and LISP certainly are as far apart as anything else, and Python is as "functional" as any other imperative language.

But Scala indeed is very similar to (1) OCaml and then (2) ML, and last, (3) Haskell in terms of type inference, syntax, and many other FP concepts [1].

[1] http://www.appservgrid.com/hyper/hyp/ml


Fair enough, thanks for the pointer :)


Scala is Hindley-Milner?


http://www.scala-lang.org/old/node/4654

(Short answer: No, because it has [to support] subtypes.)


I just started learning F# with the help of a well known F# dev. It's been a fun challenge. Give yourself the chance to try it out. Do check out http://fsharpforfunandprofit.com Its a great resource.


I worked through quite a few of the exercises on http://exercism.io/ and can recommend the challenge and the community around it for learning by writing code.


Nice, thx. Ill check it out.


I'd especially recommend this article: http://fsharpforfunandprofit.com/posts/is-your-language-unre... for a very convincing counter-argument to my thinking about #c had enough functional features that learning f# isn't worth it. It's very high on my todo list basically because of this article.


That site sold me on F# and functional programming! Really good content I can recommend too.

Another good Source: http://blog.ploeh.dk/


Only problem is their tutorial code is all broken, I had to visit the github link to find what was missing and add it in.


that website is gold anyway, not only for f#. Lots of nice concepts, explained simply.

And lots of good tutorial/ideas


Great video!

If you want to get an intro to the language w/o installing anything, give Jupyter notebooks a try - F# intro/tutorial:

https://notebooks.azure.com/library/fsharp/html/FSharp%20for...

(you can just browse it, or sign in to clone & run & edit & ... )


http://www.tryfsharp.org/Create

With Silverlight installed, you can try it in the browser. They really need to update this to work with just a modern browser!


When is 4.1 with .net core support going to be out?


I can do this -

PS C:\foo> dotnet --version

1.0.0-rc4-004771 <- vs 2017 RC4

PS C:\foo> dotnet new mvc -lang F#

Pretty certain this is 4.1 and already out.

Articles have been around for a while https://medium.com/real-world-fsharp/using-f-with-net-core-a...


Fsharp 4.1 does not appear to be released yet. The download for windows is still 4.0. Last I looked ionide did not support .net core. I'm betting it will be released as part of the VS 2017 visualfsharp update. They just called for help testing RC3.

I'm looking forward to the release and the subsequent smoothing of the .net core fhsarp ecosystem.


Depends what you mean released. rtm not, but rc are out, and works.

Or use VS2017-rc, to use f# 4.1 with .NET framework

Or use .NET Core sdk and .net core https://github.com/dotnet/netcorecli-fsc/wiki/.NET-Core-SDK-... the default templates use new f# 4.1

Ionide in vscode support .net core (both project.json and msbuild sdks), atm there is a temporary issues with rc4, but feel free to use a previous sdk (are really similar, no need to stay bleeding edge, and will be fixing sooner than later).

See wiki https://github.com/dotnet/netcorecli-fsc/wiki for more info about f# and .net core, or new sdk (all version, with how-to and workaround if needed)


A few things still need to be ironed up.

Expect full support around .NET Core 2.0 time.

https://github.com/Microsoft/visualfsharp/issues/2400


Awesome. IMHO to really "take off" fsharp is going to need a super smooth .net core story including .net core ionide support. It's not a sure thing, but I can't stress enough my belief in these two things:

* Seemless x-platform with dotnet core

* ionide working with dotnet core(and ideally on par with at least xamarin fsharp support)


First RTM release of VS 2017 due early March, but I think there will be many updates thereafter.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: