| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
PlutusCore
Synopsis
- parseProgram :: (Text -> m (Program TyName Name DefaultUni DefaultFun SrcSpan) #
parseTerm :: (Text -> m (Term TyName Name DefaultUni DefaultFun SrcSpan) #
Parse a PLC term. The resulting program will have fresh names. The underlying monad must be capable of handling any parse errors.
parseType :: (Text -> m (Type TyName DefaultUni SrcSpan) #
Parse a PLC type. The resulting program will have fresh names. The underlying monad must be capable of handling any parse errors.
The data type SourcePos represents source positions. It contains the
name of the source file, a line number, and a column number. Source line
and column positions change intensively during parsing, so we need to
make them strict to avoid memory leaks.
Instances
| Text.Megaparsec.Pos type Rep SourcePos = D1 ('MetaData "SourcePos" "Text.Megaparsec.Pos" "megaparsec-9.7.0-9IxnAL1Z5n8HX9bf04jh9I" 'False) (C1 ('MetaCons "SourcePos" 'PrefixI 'True) (S1 ('MetaSel ('Just "sourceName") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 FilePath) :*: (S1 ('MetaSel ('Just "sourceLine") 'NoSourceUnpackedness 'SourceStrict 'DecidedUnpack) (Rec0 Pos) :*: S1 ('MetaSel ('Just "sourceColumn") 'NoSourceUnpackedness 'SourceStrict 'DecidedUnpack) (Rec0 Pos)))) |
The span between two source locations.
This corresponds roughly to the SrcSpan used by GHC,
but we define our own version so we don't have to depend on ghc to use it.
The line and column numbers are 1-based, and the unit is Unicode code point (or Char).
Constructors
| SrcSpan | |
Fields
| |
Builtins
data Some (tag :: k -> Type) where #
Existential. This is type is useful to hide GADTs' parameters.
>>>data Tag :: Type -> Type where TagInt :: Tag Int; TagBool :: Tag Bool>>>instance GShow Tag where gshowsPrec _ TagInt = showString "TagInt"; gshowsPrec _ TagBool = showString "TagBool">>>classify s = case s of "TagInt" -> [mkGReadResult TagInt]; "TagBool" -> [mkGReadResult TagBool]; _ -> []>>>instance GRead Tag where greadsPrec _ s = [ (r, rest) | (con, rest) <- lex s, r <- classify con ]
You can either use PatternSynonyms (available with GHC >= 8.0)
>>>let x = Some TagInt>>>xSome TagInt
>>>case x of { Some TagInt -> "I"; Some TagBool -> "B" } :: String"I"
or you can use functions
>>>let y = mkSome TagBool>>>ySome TagBool
>>>withSome y $ \y' -> case y' of { TagInt -> "I"; TagBool -> "B" } :: String"B"
The implementation of mapSome is safe.
>>>let f :: Tag a -> Tag a; f TagInt = TagInt; f TagBool = TagBool>>>mapSome f ySome TagBool
but you can also use:
>>>withSome y (mkSome . f)Some TagBool
>>>read "Some TagBool" :: Some TagSome TagBool
>>>read "mkSome TagInt" :: Some TagSome TagInt
Instances
| (Closed uni, Everywhere uni PrettyConst) => PrettyBy ConstConfig (Some (ValueOf uni)) # | |
Defined in PlutusCore.Pretty.PrettyConst Methods prettyBy :: ConstConfig -> Some (ValueOf uni) -> Doc ann # prettyListBy :: ConstConfig -> [Some (ValueOf uni)] -> Doc ann # | |
| NumBits # | |
| (Closed uni, Everywhere uni PrettyConst) => Pretty (ValueOf uni a) # | |
Defined in PlutusCore.Pretty.PrettyConst | |
| (Closed uni, Everywhere uni PrettyConst) => Pretty (Some (ValueOf uni)) # | |
someValueOf :: forall a uni. uni (Esc a) -> a -> Some (ValueOf uni) #
Wrap a value into Some (ValueOf uni), given its explicit type tag.
someValue :: forall a uni. uni `Contains` a => a -> Some (ValueOf uni) #
Wrap a value into Some (ValueOf uni), provided its type is in the universe.
someValueType :: Some (ValueOf uni) -> SomeTypeIn uni #
A class for enumerating types and fully instantiated type formers that uni contains.
For example, a particular ExampleUni may have monomorphic types in it:
instance ExampleUni Contains Integer where ...
instance ExampleUni Contains Bool where ...
as well as polymorphic ones:
instance ExampleUni Contains [] where ...
instance ExampleUni Contains (,) where ...
as well as their instantiations:
instance ExampleUni Contains a => ExampleUni Contains [a] where ...
instance (ExampleUni Contains a, ExampleUni Contains b) => ExampleUni Contains (a, b) where ...
(a universe can have any subset of the mentioned sorts of types, for example it's fine to have instantiated polymorphic types and not have uninstantiated ones and vice versa)
Note that when used as a constraint of a function Contains does not allow you to directly
express things like "uni has the Integer, Bool and [] types and type formers",
because [] is not fully instantiated. So you can only say "uni has Integer, Bool,
[Integer], [Bool], [[Integer]], [[Bool]] etc" and such manual enumeration is annoying,
so we'd really like to be able to say that uni has lists of arbitrary built-in types
(including lists of lists etc). Contains does not allow that, but Includes does.
For example, in the body of the following definition:
foo :: (uni Includes Integer, uni Includes Bool, uni Includes []) => ...
foo = ...
you can make use of the fact that uni has lists of arbitrary included types (integers,
booleans and lists).
Hence most of the time opt for using the more flexible Includes.
Includes is defined in terms of Contains, so you only need to provide a Contains instance
per type from the universe and you'll get Includes for free.
Instances
| Contains DefaultUni Text) # | |
| Contains DefaultUni Vector) # | |
| Contains DefaultUni List # | |
Defined in PlutusCore.Default.Universe Methods knownUni :: DefaultUni (Esc List) # | |
| (TypeError NoStandalonePolymorphicDataErrMsg :: Constraint) => Contains uni (TyVarRep :: TyNameRep kind -> kind) # | |
Defined in PlutusCore.Builtin.Polymorphism | |
A universe is Closed, if it's known how to constrain every type from the universe and
every type can be encoded to / decoded from a sequence of integer tags.
The universe doesn't have to be finite and providing support for infinite universes is the
reason why we encode a type as a sequence of integer tags as opposed to a single integer tag.
For example, given
data U a where
UList :: !(U a) -> U [a]
UInt :: U IntUList (UList UInt) can be encoded to [0,0,1] where 0 and 1 are the integer tags of the
UList and UInt constructors, respectively.
Associated Types
type Everywhere uni (constr :: Type -> Constraint) :: Constraint #
A constrant for "constr a holds for any a from uni".
Methods
Encode a type as a sequence of Int tags.
The opposite of decodeUni.
withDecodedUni :: (forall k (a :: k). Typeable k => uni (Esc a) -> DecodeUniM r) -> DecodeUniM r #
Decode a type and feed it to the continuation.
bring :: uni `Everywhere` constr => proxy constr -> uni (Esc a) -> (constr a => r) -> r #
Bring a constr a instance in scope, provided a is a type from the universe and
constr holds for any type from the universe.
Instances
| Closed DefaultUni # | |
Defined in PlutusCore.Default.Universe Associated Types type Everywhere DefaultUni constr # Methods encodeUni :: DefaultUni a -> [Int] # withDecodedUni :: (forall k (a :: k). Typeable k => DefaultUni (Esc a) -> DecodeUniM r) -> DecodeUniM r # bring :: Everywhere DefaultUni constr => proxy constr -> DefaultUni (Esc a) -> (constr a => r) -> r # | |
type family EverywhereAll uni constrs where ... #
Equations
| EverywhereAll uni '[] = () | |
| EverywhereAll uni (constr ': constrs) = (uni `Everywhere` constr, uni `EverywhereAll` constrs) |
knownUniOf :: uni `Contains` a => proxy a -> uni (Esc a) #
Same as knownUni, but receives a proxy.
class GShow (t :: k -> Type) where #
Show-like class for 1-type-parameter GADTs. GShow t => ... is equivalent to something
like (forall a. Show (t a)) => .... The easiest way to create instances would probably be
to write (or derive) an instance Show (T a), and then simply say:
instance GShow t where gshowsPrec = defaultGshowsPrec
Methods
gshowsPrec :: forall (a :: k). GOrdering a a0 -> ShowS #
>>>gshow (Pair Refl Refl :: Product ((:~:) Int) ((:~:) Int) Int)"Pair Refl Refl"
Defined in Data.GADT.Internal
Methods
gshowsPrec :: forall (a0 :: k0). Int -> Product a b a0 -> ShowS #
>>>gshow (InL Refl :: Sum ((:~:) Int) ((:~:) Bool) Int)"InL Refl"
Defined in Data.GADT.Internal
Methods
gshowsPrec :: forall (a0 :: k0). Int -> (a :~~: a0) -> ShowS #
>>>gshow (Pair Refl Refl :: Product ((:~:) Int) ((:~:) Int) Int)"Refl :*: Refl"
Since: some-1.0.4
Defined in Data.GADT.Internal
Methods
gshowsPrec :: forall (a0 :: k0). Int -> (a :*: b) a0 -> ShowS #
>>>gshow (L1 Refl :: ((:~:) Int :+: (:~:) Bool) Int)"L1 Refl"
Since: some-1.0.4
Defined in Data.GADT.Internal
Methods
gshowsPrec :: forall (a0 :: k0). Int -> (a :+: b) a0 -> ShowS #