我应该使用GHC Haskell扩展吗? [英] Should I use GHC Haskell extensions or not?

查看:107
本文介绍了我应该使用GHC Haskell扩展吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我学习Haskell时,我发现有很多语言扩展。作为初学者,我应该学会使用它们,还是应该不惜一切代价避免它们?我发现它打破了与Haskell 98的兼容性,并且仅将代码限制在几乎GHC。但是,如果我在Hackage上浏览软件包,我会发现它们大多数都只是GHC。

因此,社区对使用语言扩展的态度如何? / p>

如果扩展的使用是可以的,我怎么能区分我可以安全使用的扩展(可能成为下一个Haskell标准的一部分)这大多是实验性的?例如,我想 -XDisambiguateRecordFields 是很好用的,但它可能在将来被支持吗?

解决方案

有一些GHC扩展也是如此好生活没有。我最喜欢的是


  • 多参数类型类

  • 作用域类型变量
  • 高级类型

  • 广义代数数据类型(GADT)


这些真正必要的是多参数类型的类。



一些GHC扩展是非常具有推测性和实验性的,您可能需要谨慎使用。确定一个稳定和可信的扩展的一个好方法是看它是否被包含在 Haskell Prime ,希望成为Haskell 98的继任者。

第二个唐斯图尔特建议每个扩展都应该使用标记, LANGUAGE 源文件中的编译指示。 不要使用命令行选项启用扩展。


As I am learning Haskell, I see that there is a lot of language extensions used in real life code. As a beginner, should I learn to use them, or should I avoid them at all cost? I see that it breaks compatibility with Haskell 98 and limits code to pretty much GHC only. However, if I browse packages on Hackage, I see that most of them are GHC-only anyway.

So, what is an attitude of community towards using language extensions?

And if use of extensions is OK, how can I distinguish extensions which I can use "safely" (those which are likely to become part of the next Haskell standard) from those which are mostly "experimental"? For example, I suppose that -XDisambiguateRecordFields is nice and useful, but is it likely to be supported in the future?

解决方案

There are some GHC extensions that are too good to live without. Among my favorites are

  • Multiparameter type classes
  • Scoped type variables
  • Higher-rank types
  • Generalized algebraic data types (GADTs)

Of these the really essential one is multiparameter type classes.

Some GHC extensions are very speculative and experimental, and you may want to use with caution. A good way to identify a stable and trusted extension is to see if it is slated for inclusion in Haskell Prime, which is hoped to be the successor the Haskell 98.

I second Don Stewart's suggestion that every extension should be marked using the LANGUAGE pragma in the source file. Don't enable extensions using command-line options.

这篇关于我应该使用GHC Haskell扩展吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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