Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the advantages of built-in immutability of F# over C#?

  1. I heard F# has native support for immutability but what about it that can not be replicated in C#? What do you get by an F# immutable data that you don't get from a C# immutable data?

  2. Also in F#, is there no way to create mutable data? Is everything immutable?

  3. If you use both C# and F# in an application, can you change the immutable F# data in C#? Or do you just have to create new C# types that uses the immutable F# data and replaces the references that points to those data?

like image 916
Joan Venge Avatar asked Sep 09 '25 17:09

Joan Venge


1 Answers

  1. The way F# works makes it easier to work with immutable data but there's nothing special that can't be done in C# in that regard. It may not provide neat syntax though.

  2. F# supports mutable data with the mutable keyword. F# is not a pure functional language. It supports imperative constructs like loops as well as functional constructs.

  3. No. Immutable types are really immutable. The .NET type system is shared across both languages. You can't change the immutable data from C# either (short of reflection and memory hacks, of course).

like image 193
mmx Avatar answered Sep 12 '25 09:09

mmx