什么是对C#F#内置不可改变的优势是什么? [英] What are the advantages of built-in immutability of F# over C#?

查看:142
本文介绍了什么是对C#F#内置不可改变的优势是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 我听说F#具有不变性,但它不能在C#中复制的原生支持呢?你说的是F#不可变的数据,你不从C#不可改变的数据得到得到什么?


  2. 此外,在F#中,有没有方法来创建可变数据?一切都一成不变?


  3. 如果您在应用程序中使用C#和F#,可以你改变在C#中永恒不变的F#的数据?或者你只需​​要创建一个使用一成不变的F#的数据和新的C#类型替代指向这些数据的参考?



解决方案

  1. 的方法F#的工作可以更容易地使用不可变的数据工作,但没有什么特别的,不能在C#在这方面做。它可能不会提供,虽然整齐的语法。


  2. F#支持与可变关键字可变数据。 F#是不是一个纯函数式语言。它支持像循环命令式结构以及功能结构。


  3. 没有。稳定的类型真的是不可变的。在.NET类型系统跨两种语言共享。你不能从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?

解决方案

  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).

这篇关于什么是对C#F#内置不可改变的优势是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆