Skip to content

Commit

Permalink
DROP? Unworking some/many implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
turion committed Mar 29, 2024
1 parent a0c5d3b commit db127e2
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions rhine/src/Data/Automaton.hs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,52 @@ instance (Alternative m) => Alternative (AutomatonT m) where
}
{-# INLINE (<|>) #-}

-- many AutomatonT {state, step} =
-- AutomatonT
-- { state = Undecided
-- , step = \case
-- Undecided ->
-- let init =
-- ( (\(Result s a) (Result manyS as) -> Result (Progress s manyS) (a : as))
-- <$> step state
-- <*> init
-- )
-- <|> pure Result {resultState = Terminated, output = []}
-- in init
-- Terminated -> pure $! Result Terminated []
-- manyS@(Progress _ _) -> _
-- }

-- FIXME Not quite the right encoding because there can't be more Undecided further down?
-- In fact I probably want a Maybe [s]?
data Many s = Undecided | Terminated | Progress s ~(Many s)
deriving (Foldable, Functor, Traversable)

mySome :: (Alternative m) => AutomatonT m a -> AutomatonT m [a]
mySome ma = let go = (:) <$> ma <*> (go <|> pure []) in go

-- X = Maybe (Either () (s, X))
myMany :: (Alternative m) => AutomatonT m a -> AutomatonT m [a]
myMany ma = let go = ((:) <$> ma <*> go) <|> pure [] in go

{-
= let go = Automaton
{ state = Nothing
, step =
maybe ((mapResultState (Just . Left) <$> (step ((:) <$> ma <*> go)) (state ((:) <$> ma <*> go)))
<|> (mapResultState (Just . Right) <$> stepR stateR0)) $
either
(fmap (mapResultState (Just . Left)) . stepL)
(fmap (mapResultState (Just . Right)) . stepR)
}
in go
-}

afix f b = let a = f $ a <|> b in a

-- mySome' :: (Alternative m) => AutomatonT m a -> AutomatonT m [a]
-- mySome' = _

instance MFunctor AutomatonT where
hoist f AutomatonT {state, step} = AutomatonT {state, step = f <$> step}
{-# INLINE hoist #-}
Expand Down

0 comments on commit db127e2

Please sign in to comment.