`do`块中的变量未找到PureScript

时间:2014-07-25 03:55:35

标签: functional-programming purescript

这不起作用:

itAsync "subscribeEventedOn should receive any attached data" $ \done -> do      
  w <- getWindow
  subscribeEventedOn "foo" (\event -> do
    fprint event
    expect (unwrapDetail event) `toDeepEqual` d'
    itIs done
  ) w
  emitOn sampleEvent w
  expect true `toEqual` true

未知值'w'

但这确实有效:

w <- getWindow
itAsync "subscribeEventedOn should receive any attached data" $ \done -> do      
  subscribeEventedOn "foo" (\event -> do
    fprint event
    expect (unwrapDetail event) `toDeepEqual` d'
    itIs done
  ) w
  emitOn sampleEvent w
  expect true `toEqual` true

为什么呢?这对我来说没有意义。 (顺便说一句,我在单元测试中嵌套了do块)

1 个答案:

答案 0 :(得分:1)

我能够通过猜测示例代码中的名称类型来重现这一点,看起来这是由PureScript词法分析器的特性引起的。你可以通过将关闭的paren移动到上面的行来修复它:

itAsync "subscribeEventedOn should receive any attached data" $ \done -> do      
  w <- getWindow
  subscribeEventedOn "foo" (\event -> do
    fprint event
    expect (unwrapDetail event) `toDeepEqual` d'
    itIs done) w
  emitOn sampleEvent w
  expect true `toEqual` true