0

I have an effectful asynchronous action with a type, let's say,

effectful :: Aff e r

I would like to build an action that takes some asynchronous action and sends the result to a Channel from purescript-signal. The send function has the signature:

send :: forall a e. Channel a -> a -> Eff (channel :: CHANNEL | e) Unit

Here is the implementation I came up with:

runAffToChannel :: forall a e. Channel a
                -> Aff e a
                -> Eff (channel :: CHANNEL | e) Unit
runAffToChannel chan = runAff_ $ either ignore $ send chan
  where
    ignore = const (pure unit)

The types do not unify here between e and channel :: CHANNEL | e.

How do I convert the value of type Aff e a to Aff (channel :: CHANNEL | e) a, or at least Eff e a to Eff (channel :: CHANNEL | e) a?

Koterpillar
  • 7,883
  • 2
  • 25
  • 41

1 Answers1

2

When using effect rows, it's generally best to use the same row everywhere even if the effects aren't "required" in every place. So in this case, the type for the Aff argument should include channel too:

runAffToChannel :: forall a e. Channel a
                -> Aff (channel :: CHANNEL | e) a
                -> Eff (channel :: CHANNEL | e) Unit

Using effect rows like this might seem not quite right (and is a little unfortunate, as it makes the rows "wider" than they need to be in some places), but it saves a lot of pain in making the rows all line up.

gb.
  • 4,629
  • 1
  • 20
  • 19