我这里有一个约克·拉瓦的功能,我想在堪萨斯重写它。但它不想工作,我也不知道我真的应该这么做。有谁能帮我一下吗?
{-Serial In - Parallel Out shiftregister. The serial bit is inserted at
the least significant bit position. The data is shifted LSB -> MSB
each and every clock cycle-}
sipo :: Int -- ^ The number of bits in the output word.
-> Bit -- ^ The input bit.
-> [Bit] -- ^ The output word.
sipo 1 inp = [inp]
sipo n inp = inp : rest
where
inp' = delay low inp
rest = sipo (n-1) inp'上面的函数给出了一些例子的正确结果:
n = 3
inp = high
out = [high, low, low]
n= 5
inp = high
out = [high, low, low, low, low]现在我试着用堪萨斯州的Lava写这个,它们是一个延迟函数,但是我得到了奇怪的结果。下面的代码生成我,其参数与第一个示例相同:
n = 3
inp = high
out = [high?, high., high!] (don't know what that means)
sipo :: (Clock clk)
=> Int -- ^ The number of bits in the output word.
-> Signal clk Bool -- ^ The input bit.
-> [Signal clk Bool] -- ^ The output word.
sipo 1 inp = [inp]
sipo n inp = inp : rest
where
inp' = delay inp
rest = sipo (n-1) inp' 发布于 2015-02-24 03:54:44
您的代码完全按照预期工作.
在GHCi的模拟器中试用您的函数,结果是:
*Main> sipo 3 (high :: Signal CLK Bool)
[high,? | high .,? | ? | high .]阅读它的方式是:
sipo 3 high !! 0 = high
sipo 3 high !! 1 = ? | high
sipo 3 high !! 2 = ? | ? | highLava模拟器的这个输出意味着第一个周期中的第一个输出是high,并且没有模拟器输入来告诉进一步的值。类似地,第二个输出在第一个周期中未定义,high在第二个周期中未定义;第三个输出在两个周期中未定义,high在第三个周期中未定义。
这是完全合理的,因为第二个输出在第一个周期中没有设置:延迟的输入信号还没有到达那里。
其结果不同于约克拉瓦的原因是,约克拉瓦的delay原语似乎需要额外的价值才能在第一个时钟周期之前使用。不过,我不确定这是可合成的。
https://stackoverflow.com/questions/23569845
复制相似问题