Skip to content

Commit

Permalink
WIP Clock erasure should happen at compile time, but can't achieve it…
Browse files Browse the repository at this point in the history
… through strictness

* Maybe through simplifying initClock (#304)
* Looking at the Core it turns out that erased clock isn't completely simplified,
  and it's somehow obvious because it can't be inlined since it's recursive
* I was hoping that if the automaton is evaluated strictly enough, it would be reduced to WHNF before reactimation starts
  but it's unclear whether this would even be visible in Core
  • Loading branch information
turion committed May 10, 2024
1 parent 0e7501b commit 23829f5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions automaton/src/Data/Stream/Optimized.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE RankNTypes #-}
Expand Down Expand Up @@ -160,8 +161,8 @@ handleOptimized f stream = Stateful $ f $ toStreamT stream
See 'Data.Stream.reactimate'.
-}
reactimate :: (Monad m) => OptimizedStreamT m () -> m void
reactimate (Stateful stream) = StreamT.reactimate stream
reactimate (Stateless f) = go
reactimate (Stateful !stream) = StreamT.reactimate stream
reactimate (Stateless !f) = go
where
go = f *> go
{-# INLINE reactimate #-}
Expand All @@ -173,7 +174,6 @@ since the optimized version doesn't create a state type.
-}
constM :: m a -> OptimizedStreamT m a
constM = Stateless
{-# INLINE constM #-}

-- | Perform one step of a stream, resulting in an updated stream and an output value.
stepOptimizedStream :: (Functor m) => OptimizedStreamT m a -> m (Result (OptimizedStreamT m a) a)
Expand Down
3 changes: 2 additions & 1 deletion rhine/src/FRP/Rhine/Reactimation.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE GADTs #-}

{- |
Expand Down Expand Up @@ -55,7 +56,7 @@ flow ::
Rhine m cl () () ->
m void
flow rhine = do
automaton <- eraseClock rhine
!automaton <- eraseClock rhine
reactimate $ automaton >>> arr (const ())
{-# INLINE flow #-}

Expand Down

0 comments on commit 23829f5

Please sign in to comment.