- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 ghci 中:
λ> :t (pure 1)
(pure 1) :: (Applicative f, Num a) => f a
λ> show (pure 1)
<interactive>:1:1:
No instance for (Show (f0 a0))
arising from a use of `show'
Possible fix: add an instance declaration for (Show (f0 a0))
In the expression: show (pure 1)
In an equation for `it': it = show (pure 1)
λ> pure 1
1
IO
?
pure ()
和
pure (+1)
不要打印任何东西。
最佳答案
如果你使用 return
,你会得到相同的行为。而不是 pure
.要找出要做什么,ghci 必须为给定的表达式选择一个类型。 ghci 的默认规则是在没有其他约束的情况下,它选择 IO
对于 Applicative
或 Monad
实例。因此它解释 pure 1
作为 IO Integer
类型的表达式. IO a
类型的表达式如果为 1,则执行在提示符处输入并打印其结果。a
有一个 Show
实例和 2。a
不是 ()
.从而输入pure 1
在提示的结果
v <- return (1 :: Integer)
print v
return v
it
绑定(bind)到返回的
v
)。对于
pure ()
, 特殊情况适用于
()
被认为是无趣的,因此只有
return ()
被执行并且
it
绑定(bind)到
()
, 对于
pure (+1)
,返回一个函数,没有
Show
范围内的函数的实例,因此不会打印任何内容。然而,
Prelude Control.Applicative> :m +Text.Show.Functions
Prelude Control.Applicative Text.Show.Functions> pure (+1)
<function>
it :: Integer -> Integer
Prelude Control.Applicative Text.Show.Functions> it 3
4
it :: Integer
Show
范围内的函数的实例,它被打印出来(不是提供信息),然后可以使用该函数(后者独立于
Show
实例在范围内,当然)。
关于haskell - Applicative 的 ghci 特例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7949464/
数组的倒置计数表示——数组离排序有多远(或接近)。如果数组已经排序,则反转计数为 0。如果数组以相反的顺序排序,则反转计数为最大值。形式上来说,如果 a[i] > a[j] 且 i < j,则两个元素
假设我有两座建筑物,我可以在其中 build 不同的单元。一个建筑物只能同时 build 一个单元,但有一个最多 5 个单元的 fifo 队列,它们将按顺序 build 。每个单元都有构建时间。我需要
我正在执行一个查询并从数组中的数据库中获取以下数据(MySql2 类型对象): +-----------+---------------+---------------+------+------+
在 ghci 中: λ> :t (pure 1) (pure 1) :: (Applicative f, Num a) => f a λ> show (pure 1) :1:1: No ins
在这种特殊情况下,我不会让 file_get_contents() 返回页面,其中 url 包含一个“Ö”字符。 $url = "https://se.timeedit.net/web/liu/db1
这是我的字符串10000000000000000000000000000000000000000000000000000000000 与 60 1/0 组合的字符串。 我想把它放入一个 int Arr
你好, 我有以下代码: 43 while (TRUE) 44 { 45 printf("Swipe Card: "); 46 scanf("%s
我正在寻找在多项式时间内解决的 3-SAT 特例及其算法。任何链接? 谢谢。 最佳答案 阅读 Thomas J Schaeffer 的优秀(但有点难以阅读)论文:The Complexity of S
我正在清理我的一个旧项目。它必须做的一件事是——给定笛卡尔网格系统和网格上的两个正方形,找到所有正方形的列表,连接这两个正方形中心的线将通过这些正方形。 这里的特殊情况是所有起点和终点都被限制在正方形
如果你在“alloc.c”中有如下代码: typedef __typeof__(sizeof(int)) size_t; extern void *calloc (size_t __nmemb, si
我在 Ruby 中有一个数组,其值如下 xs = %w(2.0.0.1 2.0.0.6 2.0.1.10 2.0.1.5 2.0.0.8) 等等。我想对数组进行排序,使最终结果应该是这样的: ys =
关于将应用程序提交到 iOS AppStore,我遇到了一个非常独特的困境。 这是一款适用于 1.5 至 3 岁 child 的应用程序,该应用程序背后的想法是通过语音引导您学习动物名称和它们的声音。
我是一名优秀的程序员,十分优秀!