module Darcs.Patch.Witnesses.Maybe
  ( Maybe2(..)
  , maybeToFL, maybeToRL
  , mapMB_MB
  ) where

import Darcs.Patch.Witnesses.Ordered ( FL(..), RL(..) )

data Maybe2 p wX wY where
  Nothing2 :: Maybe2 p wX wX
  Just2 :: p wX wY -> Maybe2 p wX wY

maybeToFL :: Maybe2 p wX wY -> FL p wX wY
maybeToFL :: forall (p :: * -> * -> *) wX wY. Maybe2 p wX wY -> FL p wX wY
maybeToFL Maybe2 p wX wY
Nothing2 = FL p wX wX
FL p wX wY
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL
maybeToFL (Just2 p wX wY
v) = p wX wY
v p wX wY -> FL p wY wY -> FL p wX wY
forall (a :: * -> * -> *) wX wY wZ.
a wX wY -> FL a wY wZ -> FL a wX wZ
:>: FL p wY wY
forall (a :: * -> * -> *) wX. FL a wX wX
NilFL

maybeToRL :: Maybe2 p wX wY -> RL p wX wY
maybeToRL :: forall (p :: * -> * -> *) wX wY. Maybe2 p wX wY -> RL p wX wY
maybeToRL Maybe2 p wX wY
Nothing2 = RL p wX wX
RL p wX wY
forall (a :: * -> * -> *) wX. RL a wX wX
NilRL
maybeToRL (Just2 p wX wY
v) = RL p wX wX
forall (a :: * -> * -> *) wX. RL a wX wX
NilRL RL p wX wX -> p wX wY -> RL p wX wY
forall (a :: * -> * -> *) wX wY wZ.
RL a wX wY -> a wY wZ -> RL a wX wZ
:<: p wX wY
v

mapMB_MB :: (p wX wY -> q wX wY) -> Maybe2 p wX wY -> Maybe2 q wX wY
mapMB_MB :: forall (p :: * -> * -> *) wX wY (q :: * -> * -> *).
(p wX wY -> q wX wY) -> Maybe2 p wX wY -> Maybe2 q wX wY
mapMB_MB p wX wY -> q wX wY
_ Maybe2 p wX wY
Nothing2 = Maybe2 q wX wX
Maybe2 q wX wY
forall (p :: * -> * -> *) wX. Maybe2 p wX wX
Nothing2
mapMB_MB p wX wY -> q wX wY
f (Just2 p wX wY
v) = q wX wY -> Maybe2 q wX wY
forall (p :: * -> * -> *) wX wY. p wX wY -> Maybe2 p wX wY
Just2 (p wX wY -> q wX wY
f p wX wY
v)