-
Notifications
You must be signed in to change notification settings - Fork 485
[Builtins] Allow casing on booleans and integers #7029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
06d1a16
2c5a658
89f9909
9e65c92
5f0c523
50689dc
d0a5a27
43789e2
8173d7c
15f15b9
eaf8284
7c5387e
b63ff2f
35c61d8
dafd361
9ac9643
5fad6c1
7826ad0
b5aff71
d404be1
81948ad
82d703f
cabbbe3
8d72e6c
2748dbb
2338a26
7901ba5
d221ef4
9fa4ef3
29c1442
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-- case of non-constr | ||
(program 1.1.0 | ||
(case (con integer 1) (lam x x) (lam x x)) | ||
(case (lam x x) (lam x x) (lam x x)) | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE RankNTypes #-} | ||
{-# LANGUAGE TypeOperators #-} | ||
|
||
module PlutusCore.Builtin.Case where | ||
|
||
import PlutusCore.Core.Type (Type, UniOf) | ||
import PlutusCore.Name.Unique | ||
|
||
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 | ||
-- | Given a tag for a built-in type and a list of branches, annotate each of the branches with | ||
-- its expected argument types or fail if casing on values of the built-in type isn't supported. | ||
annotateCaseBuiltin | ||
:: UniOf term ~ uni | ||
=> SomeTypeIn uni | ||
-> [term] | ||
-> Either Text [(term, [Type TyName uni ann])] | ||
|
||
class CaseBuiltin uni where | ||
-- | Given a constant with its type tag and a vector of branches, choose the appropriate branch | ||
-- or fail if the constant doesn't correspond to any of the branches (or casing on constants of | ||
-- this type isn't supported at all). | ||
caseBuiltin :: UniOf term ~ uni => Some (ValueOf uni) -> Vector term -> Either Text term | ||
|
||
data CaserBuiltin uni = CaserBuiltin | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems Also, why not newtype? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ok, so
Create a Note and link to it? |
||
{ unCaserBuiltin | ||
:: !(forall term. UniOf term ~ uni => Some (ValueOf uni) -> Vector term -> Either Text term) | ||
} | ||
|
||
instance NFData (CaserBuiltin uni) where | ||
rnf = rwhnf | ||
|
||
deriving via OnlyCheckWhnfNamed "PlutusCore.Builtin.Case.CaserBuiltin" (CaserBuiltin uni) | ||
instance NoThunks (CaserBuiltin uni) | ||
|
||
instance CaseBuiltin uni => Default (CaserBuiltin uni) where | ||
def = CaserBuiltin caseBuiltin | ||
|
||
unavailableCaserBuiltin :: Int -> CaserBuiltin uni | ||
unavailableCaserBuiltin ver = | ||
CaserBuiltin $ \_ _ -> Left $ | ||
"'case' on values of built-in types is not supported in protocol version " <> display ver |
Uh oh!
There was an error while loading. Please reload this page.