Fusion: actually implement list rewrite rule

fogti
Aug 22, 2024, 2:51 PM
G64LUZSXYNCYM6OBDLBOCQODNVOF7EM4DUA2IFP43FR46RA5VR3AC

Dependencies

  • [2] 6XMVEBZA add simple stuff (e.g. haskell basics)

Change contents

  • edit in core/lib/GardGround/Utils/Fusion.hs at line 7
    [2.1890][2.1890:1904]()
    runSteps,
  • replacement in core/lib/GardGround/Utils/Fusion.hs at line 9
    [2.1933][2.1933:1948]()
    runStream,
    [2.1933]
    [2.1948]
    stream,
    unstream,
  • replacement in core/lib/GardGround/Utils/Fusion.hs at line 72
    [2.3472][2.3472:3535]()
    runSteps :: StepFun s a -> s -> [a]
    runSteps (StepFun sf) = go
    [2.3472]
    [2.3535]
    data Stream a = forall s. Stream
    (StepFun s a) -- ^ stepper function
    !s -- ^ current state
    instance Functor Stream where
    fmap f (Stream step_ cst) = Stream (fmap f step_) cst
    unstream :: Stream a -> [a]
    unstream (Stream (StepFun sf) ctx) = go ctx
  • edit in core/lib/GardGround/Utils/Fusion.hs at line 86
    [2.3643]
    [2.3643]
    {-# INLINE [0] unstream #-}
  • replacement in core/lib/GardGround/Utils/Fusion.hs at line 88
    [2.3644][2.3644:3758]()
    data Stream a = forall s. Stream
    (StepFun s a) -- ^ stepper function
    !s -- ^ current state
    [2.3644]
    [2.3758]
    -- | convert a list to a stream
    stream :: [a] -> Stream a
    stream = Stream (StepFun go)
    where
    go [] = Done
    go (x:xs) = Yield x xs
    {-# INLINE [0] stream #-}
  • replacement in core/lib/GardGround/Utils/Fusion.hs at line 96
    [2.3759][2.3759:3946]()
    instance Functor Stream where
    fmap f (Stream step_ cst) = Stream (fmap f step_) cst
    runStream :: Stream a -> [a]
    runStream (Stream sf ctx) = runSteps sf ctx
    {-# INLINE runStream #-}
    [2.3759]
    [2.3946]
    {-# RULES
    "gardground stream/unstream" forall (s :: Stream a). stream (unstream s) = s
    #-}