Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get keyboard event in purescript

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?

like image 401
hamza mah Avatar asked Jun 16 '26 09:06

hamza mah


1 Answers

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 
like image 117
Fyodor Soikin Avatar answered Jun 18 '26 00:06

Fyodor Soikin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!