Hacker News new | ask | show | jobs
by michaelochurch 4134 days ago
OP: a question about some of your earlier work. In particular, I'm reading through your "A Monad For Reactive Programming, Part 1". https://www.fpcomplete.com/user/agocorona/a-monad-for-reacti...

I see a lot of higher-rank types, like this:

    data Event = forall a. Event EvType a
as opposed to:

    data Event a = Event EvType a
These mean different things. In the former, an Event has to be able to hold any a, and that doesn't really make sense (unless I'm misinterpreting something) because the only value that inhabits all types a is undefined/bottom.

Or is that what you want? Is there a reason why you use higher-rank types (which make my brain hurt, require a lot of language extensions, etc.) rather than parameterized types? If so, could you spell that out?

Another example is this:

    data EventF = forall m b c. EventF  (b → Transient m c) 
Again, I'm not really familiar with what you're doing so it's quite possible that using higher-rank types is exactly what you want (see: ST Monad and Lenses, where rank-2 types are crucial). I'm just having a hard time seeing it.

Thanks!

1 comments

Hi

In the case of events, it is because I later have to store different event types in a List

so I define the list as [Event] . That is the container that feed the monad with events.

If I define Event as you suggest, I would need a existential type anyway.

    data Event a = Event EvType a

    data ListEvents= forall a.[Event a]
In the case of the continuations, I need to use a state monad that store this EventF data And I need to "erase" in some way the types to allow it to store them all for all events, no matter wich a and b they produce. I know that if in

    x :: IO a

    f :: a -> m b
If within the monad definition I store f (the rest of the computation) in the state monad, the type of this continuation when executed will be (m b) and it accept values of type `a` so I can coerce the continuation to this type even if I "erased" it when i put it in the state monad.

Anyway this approach has some problems that I solved in the second part