无法理解Haskell/Clash中奇怪的“where”语法

问题描述 投票:0回答:1

我对 Haskell 还很陌生,目前正在做一个 Clash 项目。我花了几天的时间来理解这些代码在 Haskell 中的含义:

一个例子来自复古冲突一书 https://github.com/gergoerdi/retroclash-book-code/blob/master/src/serial/echo/src/Serial.hs

topEntity
    :: "CLK" ::: Clock System
    -> "RX"  ::: Signal System Bit
    -> "TX"  ::: Signal System Bit
topEntity = withResetEnableGen board
  where
    board rx = tx
      where
        input = serialRx @8 (SNat @9600) rx
        buf = fifo input txReady
        (tx, txReady) = serialTx @8 (SNat @9600) buf

makeTopEntity 'topEntity

让我感到困惑的第一件事是,为什么我们可以拥有

board rx = tx
? 就像如果有
board = some-expression
对我来说更容易理解,因为在前面的上下文中刚刚提到了标识“板”。但是
rx
怎么也出现在等号左边呢?与模式匹配有关吗? (如果是,
rx
如何匹配?就像
topEnity
的定义中没有提到
rx
?)

另外,我无法理解这三行内部'where',不同函数名之间的关系看起来很复杂。

haskell functional-programming clash
1个回答
0
投票
board rx = tx

这定义了一个名为

board
的函数,带有一个名为
rx
的参数。调用此函数的结果是
tx
的值,该值在
where
子句中定义。

© www.soinside.com 2019 - 2024. All rights reserved.