实现系数的整数 [英] Implementing Stream Integer for Coefficients
问题描述
作为作业的一部分(来自2013),我自学,考虑以下背景:
基本想法是使用表单的生成函数
a0 + a1 * x + a2 * x ^ 2 + ... + an * x ^ n +。 。 。
其中x仅仅是一个形式参数(也就是说,我们绝不会用
x替代任何值;我们只是将它用作占位符)所有系数ai都是
整数。我们将存储系数a0,a1,a2,...。 。 。在流
整数。
我试图实现 x :: Stream Integer
$ blockquote
注意到x = 0 + 1x + 0x ^ 2 + 0x ^ 3 +。 。 。 。
x :: Stream Integer
x = Cons 0(Cons 1 $ streamRepeat 0)
定义如下:
data stream a = Cons a(Stream a)
streamRepeat :: a - > Stream a
streamRepeat x = Cons x(streamRepeat x)
我的 x
执行正确吗?我不知道,鉴于上述背景,我正确地捕获了a0,a1,...,an的系数。
streamRepeat
定义,但这对作业的目的无关紧要。 As part of a homework (from 2013) for which I'm self-learning, consider the following background:
The essential idea is to work with generating functions of the form
a0 + a1*x + a2*x^2 + · · · + an*x^n + . . .
where x is just a "formal parameter" (that is, we will never actually substitute any values for x; we just use it as a placeholder) and all the coefficients ai are integers. We will store the coefficients a0, a1, a2, . . . in a Stream Integer.
I attempted to implement x :: Stream Integer
by noting that x = 0 + 1x + 0x^2 + 0x^3 + . . . .
x :: Stream Integer
x = Cons 0 (Cons 1 $ streamRepeat 0)
for the following definitions:
data Stream a = Cons a (Stream a)
streamRepeat :: a -> Stream a
streamRepeat x = Cons x (streamRepeat x)
Is my x
implementation correct? I'm not sure if, given the above background, I'm properly capturing the coefficients of a0, a1, ..., an.
Yes, it's correct. You could slightly improve streamRepeat
definition by adding sharing, but this shouldn't matter for the homework's purposes.
这篇关于实现系数的整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!