[<<][haskell][>>][..]
Mon Feb 3 09:11:45 EST 2020

A long standing problem: link pure stream view and stateful implementation

I have something that behaves as a pure function: a causal stream
processor.  Output streams _only_ depend on input streams.

However to implement this in a way that can be reified as state
machines, I am forced to use a monadic representation:

say:

accumulate_v :: v -> m v

Where v is the value type.  This is a stateful operation that computes
the instantaneous output value as the sum of the the current input
value and the hidden internal state.

The monad is necessary to implement the state, but can also be used to
hide a compiler that would e.g. be used to produce C or Verilog
output.


What I really want to do is to create functions like:

accumulate_s :: s -> s

That operate abstractly on the stream type in a way that exposes their
purity, but then can be mapped back to implementation using

comp :: (s -> s) -> (v -> m v)

Is this possible?


The only thing I've found up to now is Conal's CCC approach that
essentially redefines evaluation at a very deep level and doesn't seem
possible without a plugin.  Is there another way?



EDIT: I went down this path before, and then part of the solution was
existential types, but it still did not solve the sharing problem.  It
seems that strictness (an effect!) is baked into this problem in a
very deep way.

So let's stick to this conclusion for now: there is no way to do this
other than using CCC.

Here's a possible lead:
http://www.philipzucker.com/approximating-compiling-categories-using-typelevel-haskell-take-2/

Next step?
- Go over Conal's presentation again
- Check Oleg's embedding: http://okmij.org/ftp/Haskell/de-typechecker.lhs

For now, just stick with monadic primitives.  It's just inconvenient,
not a show stopper.




[Reply][About]
[<<][haskell][>>][..]