mirror of
https://github.com/github/semantic.git
synced 2024-12-25 16:02:43 +03:00
Define an eliminator for statements.
This commit is contained in:
parent
16413e1e5b
commit
6050b9594d
@ -9,6 +9,7 @@ module Data.Core
|
||||
, unseqs
|
||||
, (>>>=)
|
||||
, unbind
|
||||
, unstatement
|
||||
, do'
|
||||
, (:<-)(..)
|
||||
, lam
|
||||
@ -137,6 +138,9 @@ unbind :: (Alternative m, Member Core sig, RightModule sig) => a -> Term sig a -
|
||||
unbind n (Term sig) | Just (Named u a :>>= b) <- prj sig = pure (Named u n :<- a, instantiate1 (pure n) b)
|
||||
unbind _ _ = empty
|
||||
|
||||
unstatement :: (Alternative m, Member Core sig, RightModule sig) => a -> Term sig a -> m (Maybe (Named a) :<- Term sig a, Term sig a)
|
||||
unstatement n t = first (first Just) <$> unbind n t <|> first (Nothing :<-) <$> unseq t
|
||||
|
||||
do' :: (Eq a, Foldable t, Carrier sig m, Member Core sig) => t (Maybe (Named a) :<- m a) -> m a
|
||||
do' bindings = fromMaybe unit (foldr bind Nothing bindings)
|
||||
where bind (n :<- a) v = maybe (a >>>) ((>>>=) . (:<- a)) n <$> v <|> Just a
|
||||
|
Loading…
Reference in New Issue
Block a user