News for hackers. Stuff that matters.
Re:Why Use F#? by knocte on Wednesday December 12, 2018 @11:08PM (#18669785)
I haven't really played much with Scala but I would say there are reasons why I will not and stick to F#:

- JVM is less efficient for generics than the CIL (casts happening at runtime underneath).

- I've read about horror stories about tailcalls in the JVM world.

- There's no way to build an iOS app with Scala (i.e.: https://stackoverflow.com/questions/13460780/any-way-to-use-... ), while you can do easily with F# thanks to Xamarin.

Re:Why Use F#? by invalidname on Thursday December 13, 2018 @02:20AM (#18670453)
The answers there aren't up to date, here's a new answer https://stackoverflow.com/a/53756826/756809
Re:Why Use F#? by pjmlp on Thursday December 13, 2018 @12:45AM (#18670135)
There is way for free with CodenameOne.

And there is another way paying for GluonVM.

EDIT: corrected my statements based on comment below.

Re:Why Use F#? by invalidname on Thursday December 13, 2018 @02:15AM (#18670431)
Codename One has a free tier that allows you to do pretty much everything and allows you to use it commercially https://help.codenameone.com/en-us/article/is-codename-one-f...

You can grow the build quotas as well to support larger applications. Furthermore, you can use the open source pieces of Codename One for free without the build servers. There is no restriction on that.

Re:Why Use F#? by pjmlp on Thursday December 13, 2018 @02:29AM (#18670489)
Thanks for clarifying that up, I do not follow up on it that closely.
Re:Why Use F#? by azolotko on Thursday December 13, 2018 @12:54AM (#18670180)
JVM knows nothing about generics. What kind of casts are you talking about?

Trampolines are a common technique to implement tailcalls on platforms that don't support them natively. What are the horror stories then?

Why would you bother with F# or Scala when iOS has Swift?

Re:Why Use F#? by knocte on Thursday December 13, 2018 @01:41AM (#18670332)
> JVM knows nothing about generics. What kind of casts are you talking about?

Precisely! because the bytecode doesn't know about generics (it's syntactic sugar in higher levels, i.e. Java), then casts need to be performed at runtime (e.g. when getting an item from a collection).

> What are the horror stories then?

https://stackoverflow.com/a/18196685/544947

> Why would you bother with F# or Scala when iOS has Swift?

Haha, thanks for agreeing with me that Scala is not good in this regard. When I choose F# over Scala is because it can run in any platform. I'm not constrained.

Re:Why Use F#? by azolotko on Thursday December 13, 2018 @03:13AM (#18670671)
I suppose you meant boxing/unboxing. If so, yes, that's necessary for primitive types. As for regular objects, no casts are needed.

Regarding TCO, that's a well known limitation of the current Scala compiler. Hardly a "horror story".

Let me assure you, there are plenty of platforms where F# is nowhere to be seen. Thus, "can run on any platform [I care about]", which is a different set for different people anyway. For example, F# does not run on JVM, does it?

Re:Why Use F#? by knocte on Thursday December 13, 2018 @03:48AM (#18670844)
Dude, JVM is not a platform but a runtime. Why is it relevant to run F# on JVM? The important thing is to run F# in any hardware/OS, that's my point.

> As for regular objects, no casts are needed.

Are you sure? See https://stackoverflow.com/a/10126425/544947

> Hardly a "horror story".

F# doesn't have this limitation and F# does tailcalls by default instead of having to explicitly remember to decorate it with the @tailrec attribute.

Re:Why Use F#? by azolotko on Thursday December 13, 2018 @04:27AM (#18671010)
You have a pretty narrow definition of a platform. Consider https://en.m.wikipedia.org/wiki/Computing_platform

Yes, you are right, I didn't consider the checkcast instruction.

Yes, F# does not have this particular limitation, but has few of its own in different places. Most notably, it lacks HKT (arguably, because of CLR awareness of generics).

BTW, alternative approaches to stack-safe recursion do exist in Scala. For example, https://github.com/slamdata/matryoshka

Re:Why Use F#? by knocte on Friday December 14, 2018 @03:49AM (#18679418)
> Yes, F# does not have this particular limitation

And guess what? it doesn't have it because F# doesn't run on the JVM! If it run in the JVM, it would have it. So your obsession with "runtime" as a platform not only not useful, it's asking for trouble! ;)

Re:Why Use F#? by kod on Thursday December 13, 2018 @01:27PM (#18674705)
Sounds like you are confused about what @tailrec does.

@tailrec is not necessary to enable tailcalls.

All the annotation does is error if a function is not able to be optimized for tail calls.

The (attempt at) optimization takes place either way, you don't need the annotation unless there's some doubt in your mind.