1

以下代码会产生此错误:

module Broken1 where

import Control.Monad.Aff.Class (MonadAff)
import Control.Monad.Aff (Aff())
import DOM.HTML.Types
import Halogen
import DOM
import Control.Monad.Eff.Exception
import Control.Monad.Aff.AVar
import Prelude

import qualified Halogen.HTML.Indexed as H

data State = State
data Query a = Query a

ui :: forall eff g. (MonadAff (HalogenEffects eff) g) => Component State Query g
ui = component (\_ -> H.div_ []) (\(Query next) -> pure next)

main' :: forall eff a. (HTMLElement -> Aff (HalogenEffects eff) a) 
                 -> Aff (HalogenEffects eff) Unit
main' addToDOM = do
    { node: node, driver: driver } <- runUI ui State

    let driver' :: Natural Query (Aff (HalogenEffects eff))
        driver' = driver

    return unit

错误:

  at Broken1.purs line 34, column 19 - line 36, column 5

    Could not match type
      a2
    with type
      a1

  while trying to match type a2
    with type a1
  while checking that expression driver
    has type Query a1 -> Aff ( avar :: AVAR
                             , err :: EXCEPTION
                             , dom :: DOM
                             | eff1
                             )
                         a1
  in value declaration main'

如果我省略 的类型签名driver',则不会出现编译器错误,正如我所希望的那样。如果我要求psc签名(通过将类型替换为_),建议如下:

Wildcard type definition has the inferred type

forall a. Query a -> Aff ( dom :: DOM
                         , err :: EXCEPTION
                         , avar :: AVAR
                         | eff4
                         )
                     a

当我将其剪切并粘贴到代码中而不是原始类型时,错误与上述相同。

在第二种情况下,这实际上是有道理的,因为量词为 a 打开了一个新的范围,应该在 main' 的签名中捕获它。但即使我删除forall a,类型错误仍然存​​在。

garyb 今天早些时候在#purescript 上说这可能是类型检查器中的一个错误。无论如何,我都会在此处发布此内容,直到确定事实为止。

谢谢!(:

4

0 回答 0