针对电子的Thermite中的Node.js效应

时间:2016-09-18 09:39:29

标签: reactjs electron purescript

我正在尝试展开https://github.com/kRITZCREEK/electron-apps-with-purescript以为我将显示其文件名的目录添加输入。

但是,我无法将以下函数用于typecheck(最后两行有问题,最后一行是第53行):

performAction :: T.PerformAction _ State _ Action
performAction (SetEditText s)           _ _ = void do
  T.cotransform $ _ { dir = s }
performAction (UpdateFiles s)           _ _ = void do
   filenames <- either (const []) id <$> try (readdir s)
   T.cotransform $ _ { names = filenames }

这里readdir来自Node.FS.Sync并具有签名

forall eff. String -> Eff (fs :: FS, err :: EXCEPTION | eff) (Array String)

并且performAction属于

类型
forall t39 t40. Action -> t40 -> {dir :: String, names :: Array String} -> FreeT (CoTransform (Maybe {dir :: String, names :: Array String}) ({dir :: String, names :: Array String} -> {dir :: String, names :: Array String}))

实际错误是

Could not match type at line 53 col 4

FreeT
  (CoTransform t2
     ({ files :: t3
      | t4
      }
      -> { files :: Array String
         | t4
         }
     )
  )
with type
Eff
while trying to match type FreeT
                         (CoTransform t2
                            ({ files :: t3
                             | t4
                             }
                             -> { files :: Array String
                                | t4
                                }
                            )
                         )
                         t5
with type Eff
          ( fs :: FS
          | t0
          )
while checking that expression (apply cotransform) (\$1 ->
                                                  $1 { files = f
                                                     }
                                               )
has type Eff
         ( fs :: FS
         | t0
         )
         t1
in value declaration performAction
where t1 is an unknown type
  t0 is an unknown type
  t2 is an unknown type
  t5 is an unknown type
  t4 is an unknown type
  t3 is an unknown type

(整个项目可在https://github.com/MarkusBarthlen/electron-apps-with-purescript/blob/master/src/Main.purs下找到)

我怀疑我必须使用任何升降机/升降机/升降机/升降机。然而,

performAction :: T.PerformAction _ State _ Action
performAction (UpdateFiles s)           _ _ = void do
   filenames <-  ( lift (either (const []) id <$> try (readdir s)))
   T.cotransform $ _ { names = filenames }

结果

    Could not match type at line 55 col 47
    Eff
     with type
    Aff
    while trying to match type Eff
                         ( fs :: FS
                         | t1
                         )
    with type Aff t0

1 个答案:

答案 0 :(得分:4)

你可以使用它:

performAction :: forall e. T.PerformAction (fs :: FS | e) State _ Action
performAction (SetEditText s)           _ _ = void do
  T.cotransform $ _ { dir = s }
performAction (UpdateFiles s)           _ _ = void do
   filenames <- lift (liftEff (either (const []) id <$> try (readdir s)))
   T.cotransform $ _ { names = filenames }
  -- T.cotransform $ _ { dir = ""}

liftEffEff带到Afflift,然后将其提升到Thermite使用的FreeT ...。额外的lift不应该是必要的,但我认为问题是这里的行和类型类的类型推断,并且下一个版本的情况应该会更好,我们很可能会有函数依赖。