[Haskell-cafe] Help me refactor this type!

Luke Palmer lrpalmer at gmail.com
Thu Apr 24 20:06:23 EDT 2008


On Thu, Apr 24, 2008 at 11:10 PM, Ryan Ingram <ryani.spam at gmail.com> wrote:
> More FRP stuff: a new type for Future that came to me in an
>  inspiration this morning.  But it's ugly and I need someone with
>  better theoretical underpinnings than me to tell me what I've really
>  built :)
>
>  data Future t a =
>     Known t a
>   | Unknown (t -> IO (STM (Maybe (Future t a))))

This looks similar to my friend the "free monad over exponentiation",
or Suspend, which I also discovered while experimenting with FRP.
After experimenting a bit, I found that the following variant lead to
more elegant implementations of the same things:

  newtype SuspendT v m a
    = SuspendT (m (Either a (v -> SuspendT v m a)))

Implemented pretty fully here:
http://luqui.org/git/?p=luqui-misc.git;a=blob;f=work/code/haskell/frp/Fregl/Suspend.hs;h=d5d2daa02c9c392ac3788c3346fb8b6ab6acabf7;hb=63f7752229e63bd8d1aa9a7a9a8d6a785669cd45

I'm not quite sure whether you can make it have all the capabilities
yours does (there is no STMT...).

Luke


More information about the Haskell-Cafe mailing list