{-# OPTIONS --cubical --safe #-}

open import Prelude
open import Algebra

module Data.Maybe.Monoid {โ„“} {๐‘† : Type โ„“} (sgr : Semigroup ๐‘†) where

open import Data.Maybe

open Semigroup sgr

_ยซโˆ™ยป_ : Maybe ๐‘† โ†’ Maybe ๐‘† โ†’ Maybe ๐‘†
nothing ยซโˆ™ยป y = y
just x ยซโˆ™ยป nothing = just x
just x ยซโˆ™ยป just y = just (x โˆ™ y)

maybeMonoid : Monoid (Maybe ๐‘†)
maybeMonoid .Monoid._โˆ™_ = _ยซโˆ™ยป_
maybeMonoid .Monoid.ฮต = nothing
maybeMonoid .Monoid.assoc nothing y z = refl
maybeMonoid .Monoid.assoc (just x) nothing z = refl
maybeMonoid .Monoid.assoc (just x) (just xโ‚) nothing = refl
maybeMonoid .Monoid.assoc (just x) (just y) (just z) = cong just (assoc x y z)
maybeMonoid .Monoid.ฮตโˆ™ _ = refl
maybeMonoid .Monoid.โˆ™ฮต nothing = refl
maybeMonoid .Monoid.โˆ™ฮต (just x) = refl