3

I want to get keydown event in purescript so I used DomEvent. Here is my code.

main :: Eff (HA.HalogenEffects (console :: CONSOLE, timer :: T.TIMER)) Unit
main = HA.runHalogenAff do
  body <- HA.awaitBody
  cube <- runUI C.cubes unit body
  documenttarget <- liftEff $ window >>= document <#> DHT.htmlDocumentToEventTarget
  addEventListener (EventType "keydown") (eventListener test) true (documenttarget)

  H.liftEff $ T.setInterval (1000 / frameRate) do
    HA.runHalogenAff $ cube.query $ H.action C.Tick

When I try to run this code, I am getting error like this.

documenttarget <- liftEff $ window >>= document <#> DHT.htmlDocumentToEventTarget
Coudn't match type Eff with type Aff

I know aff and eff but I am new to purescript so I am not sure what I have to do to fix this issue. What can I do?

hamza mah
  • 41
  • 3

1 Answers1

2

The block that you pass to halogenRunAff is an Aff block, so every line in it must be an Aff. But liftEff returns an Eff instead. So there is a mismatch.

This is what the compiler is telling you: "can't match Eff with Aff".

To fix this, replace liftEff with liftAff:

documenttarget <- liftAff $ window >>= document <#> DHT.htmlDocumentToEventTarget 
Fyodor Soikin
  • 78,590
  • 9
  • 125
  • 172