Closed xvaldetaro closed 1 year ago
This another weird one:
module Nuts.TopLevel where
import Prelude
import App.Env (Nut_)
import Bolson.Core as Bolson
import Data.Monoid.Always (class Always)
import Deku.Control (text)
import Deku.Core (class Korok)
import Deku.DOM as D
import Effect (Effect)
import FRP.Event (AnEvent, bang, makeEvent)
usingEffect
:: forall s m lock logic obj a
. Korok s m
=> Always (m Unit) (Effect Unit)
=> m a
-> (a -> Bolson.Entity logic obj m lock)
-> Bolson.Entity logic obj m lock
usingEffect effect f =
Bolson.EventfulElement' (Bolson.EventfulElement (fromEffect (f <$> effect)))
fromEffect :: ∀ a m. Monad m => m a -> AnEvent m a
fromEffect effect = makeEvent \k -> do
emission <- effect
k emission
pure $ pure unit
nut :: ∀ s m l p. Nut_ s m l p
nut = usingEffect (pure $ bang 42) $
-- works
\myIntEv -> closureWithInt myIntEv
-- doesn't work
-- closureWithInt
where
closureWithInt :: AnEvent m Int -> Nut_ s m l p
closureWithInt myIntEv =
D.div_ [text $ show <$> myIntEv]
Don't know how I missed this - sorry about that & I'll look at this today!
Looking over this, for now I'll punt until @PureFunctor has finished up his work using Mermaid. I think that'll simplify signatures immensely.
Closing as all of these signatures are simplified now 🚀
Following up on the discussion on Discord. Got complicated cases that I got stuck with today. Tried to isolate the repro as much as I could, but I don' understand the types very well to go any further: case 1: I can't use
Nut
intopLevelNutEv
and need to specify everything. This case is a house of cards for me. Anything I change I get stuckCase 2: Just trying to create a function that returns
AnEvent
, but needed to specify all of this:Side question: I created a
type Nut_ s m l p = Korok s m => Domable m l p
so that I can create functions where the types haveAnEvent
andNut
so that we can matchm
. I.e. :nutFromRoute :: forall s m l p. AnEvent m Route -> Nut_ s m l p
Am I doing the right thing, or is there a simpler way to do this?