module Halogen.VDom.Machine
  ( Machine
  , Step (..)
  , extract
  , step
  , halt
  )
where

type Machine m a b = a -> m (Step m a b)

data Step m a b = forall s. Step b s (s -> a -> m (Step m a b)) (s -> m ())

{-# INLINE extract #-}
extract :: Step m a b -> b
extract :: forall (m :: * -> *) a b. Step m a b -> b
extract (Step b
r s
_ s -> a -> m (Step m a b)
_ s -> m ()
_) = b
r

{-# INLINE step #-}
step :: Step m a b -> a -> m (Step m a b)
step :: forall (m :: * -> *) a b. Step m a b -> a -> m (Step m a b)
step (Step b
_ s
s s -> a -> m (Step m a b)
stp s -> m ()
_) = s -> a -> m (Step m a b)
stp s
s

{-# INLINE halt #-}
halt :: Step m a b -> m ()
halt :: forall (m :: * -> *) a b. Step m a b -> m ()
halt (Step b
_ s
s s -> a -> m (Step m a b)
_ s -> m ()
h) = s -> m ()
h s
s