{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
module PlutusCore.Builtin.Case where
import PlutusCore.Builtin.KnownType (HeadSpine)
import PlutusCore.Core.Type (Type, UniOf)
import PlutusCore.Name.Unique (TyName)
import Control.DeepSeq (NFData (..), rwhnf)
import Data.Default.Class (Default (..))
import Data.Text (Text)
import Data.Vector (Vector)
import NoThunks.Class
import Text.PrettyBy (display)
import Universe
class AnnotateCaseBuiltin uni where
annotateCaseBuiltin
:: UniOf term ~ uni
=> Type TyName uni ann
-> [term]
-> Either Text [(term, [Type TyName uni ann])]
class CaseBuiltin uni where
caseBuiltin
:: UniOf term ~ uni
=> Some (ValueOf uni)
-> Vector term
-> Either Text (HeadSpine term (Some (ValueOf uni)))
data CaserBuiltin uni = CaserBuiltin
{ forall (uni :: * -> *).
CaserBuiltin uni
-> forall term.
(UniOf term ~ uni) =>
Some (ValueOf uni)
-> Vector term -> Either Text (HeadSpine term (Some (ValueOf uni)))
unCaserBuiltin
:: !(forall term. UniOf term ~ uni => Some (ValueOf uni) -> Vector term -> Either Text (HeadSpine term (Some (ValueOf uni))))
}
instance NFData (CaserBuiltin uni) where
rnf :: CaserBuiltin uni -> ()
rnf = CaserBuiltin uni -> ()
forall a. a -> ()
rwhnf
deriving via OnlyCheckWhnfNamed "PlutusCore.Builtin.Case.CaserBuiltin" (CaserBuiltin uni)
instance NoThunks (CaserBuiltin uni)
instance CaseBuiltin uni => Default (CaserBuiltin uni) where
def :: CaserBuiltin uni
def = (forall term.
(UniOf term ~ uni) =>
Some (ValueOf uni)
-> Vector term
-> Either Text (HeadSpine term (Some (ValueOf uni))))
-> CaserBuiltin uni
forall (uni :: * -> *).
(forall term.
(UniOf term ~ uni) =>
Some (ValueOf uni)
-> Vector term
-> Either Text (HeadSpine term (Some (ValueOf uni))))
-> CaserBuiltin uni
CaserBuiltin Some (ValueOf uni)
-> Vector term -> Either Text (HeadSpine term (Some (ValueOf uni)))
forall term.
(UniOf term ~ uni) =>
Some (ValueOf uni)
-> Vector term -> Either Text (HeadSpine term (Some (ValueOf uni)))
forall (uni :: * -> *) term.
(CaseBuiltin uni, UniOf term ~ uni) =>
Some (ValueOf uni)
-> Vector term -> Either Text (HeadSpine term (Some (ValueOf uni)))
caseBuiltin
unavailableCaserBuiltin :: Int -> CaserBuiltin uni
unavailableCaserBuiltin :: forall (uni :: * -> *). Int -> CaserBuiltin uni
unavailableCaserBuiltin Int
ver =
(forall term.
(UniOf term ~ uni) =>
Some (ValueOf uni)
-> Vector term
-> Either Text (HeadSpine term (Some (ValueOf uni))))
-> CaserBuiltin uni
forall (uni :: * -> *).
(forall term.
(UniOf term ~ uni) =>
Some (ValueOf uni)
-> Vector term
-> Either Text (HeadSpine term (Some (ValueOf uni))))
-> CaserBuiltin uni
CaserBuiltin ((forall term.
(UniOf term ~ uni) =>
Some (ValueOf uni)
-> Vector term
-> Either Text (HeadSpine term (Some (ValueOf uni))))
-> CaserBuiltin uni)
-> (forall term.
(UniOf term ~ uni) =>
Some (ValueOf uni)
-> Vector term
-> Either Text (HeadSpine term (Some (ValueOf uni))))
-> CaserBuiltin uni
forall a b. (a -> b) -> a -> b
$ \Some (ValueOf uni)
_ Vector term
_ -> Text -> Either Text (HeadSpine term (Some (ValueOf uni)))
forall a b. a -> Either a b
Left (Text -> Either Text (HeadSpine term (Some (ValueOf uni))))
-> Text -> Either Text (HeadSpine term (Some (ValueOf uni)))
forall a b. (a -> b) -> a -> b
$
Text
"'case' on values of built-in types is not supported in protocol version " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall str a. (Pretty a, Render str) => a -> str
display Int
ver