Haskell的隐藏功能 [英] Hidden features of Haskell
本文介绍了Haskell的隐藏功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Haskell编程语言的鲜为人知的但有用的功能是什么? (我理解语言本身是鲜为人知的,但与我一起工作,即使是解释Haskell中的简单事情,比如用一行代码定义Fibonacci序列,也会得到我的赞赏。)
- 尝试限制对Haskell核心的回答
- 每个回答一个功能
- 该功能的示例和简短描述,不仅仅是文档链接
- 使用粗体标题作为第一行标记功能
解决方案
我的大脑爆炸了
这段代码:
$ $ p $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $' Foo a
ignorefoo f = 1其中Foo a = f
您将收到此错误消息:
$ ghc Foo.hs
Foo.hs:3:22:
我的大脑爆炸了。
我无法处理存在量化构造函数的模式绑定。
相反,使用case-expression或do-notation来解压构造函数。
在绑定组中
Foo a
在模式绑定中:Foo a = f
在`ignorefoo'的定义中:
ignorefoo f = 1
其中
Foo a = f
What are the lesser-known but useful features of the Haskell programming language. (I understand the language itself is lesser-known, but work with me. Even explanations of the simple things in Haskell, like defining the Fibonacci sequence with one line of code, will get upvoted by me.)
- Try to limit answers to the Haskell core
- One feature per answer
- Give an example and short description of the feature, not just a link to documentation
- Label the feature using bold title as the first line
解决方案
My brain just exploded
If you try to compile this code:
{-# LANGUAGE ExistentialQuantification #-}
data Foo = forall a. Foo a
ignorefoo f = 1 where Foo a = f
You will get this error message:
$ ghc Foo.hs Foo.hs:3:22: My brain just exploded. I can't handle pattern bindings for existentially-quantified constructors. Instead, use a case-expression, or do-notation, to unpack the constructor. In the binding group for Foo a In a pattern binding: Foo a = f In the definition of `ignorefoo': ignorefoo f = 1 where Foo a = f
这篇关于Haskell的隐藏功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文