{-# LANGUAGE FlexibleInstances #-}

module Plutarch.Builtin.Unit (PUnit (PUnit), punit) where

import Plutarch.Internal.Term (S, Term, plet, punsafeConstantInternal)
import PlutusCore qualified as PLC

data PUnit (s :: S) = PUnit

punit :: Term s PUnit
punit :: forall (s :: S). Term s PUnit
punit = Some @Type (ValueOf DefaultUni) -> Term s PUnit
forall (s :: S) (a :: PType).
Some @Type (ValueOf DefaultUni) -> Term s a
punsafeConstantInternal (Some @Type (ValueOf DefaultUni) -> Term s PUnit)
-> Some @Type (ValueOf DefaultUni) -> Term s PUnit
forall a b. (a -> b) -> a -> b
$ () -> Some @Type (ValueOf DefaultUni)
forall a (uni :: Type -> Type).
Contains @Type uni a =>
a -> Some @Type (ValueOf uni)
PLC.someValue ()

instance Semigroup (Term s PUnit) where
  Term s PUnit
x <> :: Term s PUnit -> Term s PUnit -> Term s PUnit
<> Term s PUnit
y = Term s PUnit -> (Term s PUnit -> Term s PUnit) -> Term s PUnit
forall (s :: S) (a :: PType) (b :: PType).
Term s a -> (Term s a -> Term s b) -> Term s b
plet Term s PUnit
x ((Term s PUnit -> Term s PUnit) -> Term s PUnit)
-> (Term s PUnit -> Term s PUnit) -> Term s PUnit
forall a b. (a -> b) -> a -> b
$ \Term s PUnit
_ -> Term s PUnit -> (Term s PUnit -> Term s PUnit) -> Term s PUnit
forall (s :: S) (a :: PType) (b :: PType).
Term s a -> (Term s a -> Term s b) -> Term s b
plet Term s PUnit
y ((Term s PUnit -> Term s PUnit) -> Term s PUnit)
-> (Term s PUnit -> Term s PUnit) -> Term s PUnit
forall a b. (a -> b) -> a -> b
$ Term s PUnit -> Term s PUnit -> Term s PUnit
forall a b. a -> b -> a
const Term s PUnit
forall (s :: S). Term s PUnit
punit

instance Monoid (Term s PUnit) where
  mempty :: Term s PUnit
mempty = Term s PUnit
forall (s :: S). Term s PUnit
punit