Polymorphic instruction in Free Monad in Purescript

I am trying to compile this small piece of code.

module Sodium where

import Prelude
import Control.Monad.Free
import Data.Coyoneda
import Data.Tuple

data ReactiveF more
  = RFNewEvent (forall a. (Tuple (Event a) (a -> Reactive Unit) -> more))

type Reactive a = FreeC ReactiveF a

data Event a = Event a

newEvent :: forall a. Reactive (Tuple (Event a) (a -> Reactive Unit))
newEvent = liftFC $ RFNewEvent id

If instead of "a" in RFNewEvent instead of "a" instead of "a", everything compiles fine. But as soon as I go "forever." and replace "Number" with "a", it no longer compiles.

The following error message appears

Cannot unify type
  a1
with type
  a0

Does anyone know how to make this work?

I am using version 0.5.0 for purescript-free.

Edit

If I use the following

data NewEventData = NewEventData forall a. Tuple (Event a) (a -> Reactive Unit)

and replace it with RFNewEvent, then it will compile. But in the end, I get an invalid type signature for newEvent.

newEvent :: Reactive NewEventData
newEvent = liftFC $ RFNewEvent id

Allows me to create an event, but allows me to strip different values ​​of events into the event stream instead of the same type. (missing forall a. now on newEvent)

I could be wrong.

SodiumFRP Free Monad. JavaScript FRP, Sodium FFI Free Monad.

?

+4
1

"newEvent"

module FRP.Sodium where

import Prelude
import Control.Monad.Free
import Data.Coyoneda
import Data.Tuple

data ReactiveF more
  = RFNewEvent (NewEventData -> more)

type Reactive a = FreeC ReactiveF a

data NewEventData = NewEventData forall a. Tuple (Event a) (a -> Reactive Unit)

data Event a
  = ENever
  | EMerge (Event a) (Event a)
  | EFilterJust (Event (Maybe a))
  | ECoalesce (a -> a -> a) (Event a)
  | EOnce (Event a)
  | ESplit (Event (Array a))
  | EVar Int

data Behaviour a = BVar Int

extractNewEventData :: forall a. NewEventData -> (Tuple (Event a) (a -> Reactive Unit))
extractNewEventData (NewEventData x) = x

newEvent :: forall a. Reactive (Tuple (Event a) (a -> Reactive Unit))
newEvent = map extractNewEventData $ liftFC $ RFNewEvent id

Edit

purescript-exists. ""

RFSample ReactiveF...

.
.
.
data ReactiveF more
  = RFNewEvent (NewEventData -> more)
  | RFSample (SampleData more)
.
.
.
data SampleDataF more a = SampleDataF (Behaviour a) (a -> more)
type SampleData more = Exists (SampleDataF more)

sample :: forall a. Behaviour a -> Reactive a
sample beh = liftFC $ RFSample $ mkExists $ SampleDataF beh id

.

+3

Source: https://habr.com/ru/post/1613025/


All Articles