Skip to content

Commit

Permalink
Updated 'plutus-doc'
Browse files Browse the repository at this point in the history
  • Loading branch information
effectfully committed Sep 21, 2020
1 parent 5e5bd3d commit 470f4fe
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion doc/tutorials/BasicPolicies.hs
Expand Up @@ -35,7 +35,7 @@ oneAtATimePolicy ctx =
-- We can use 'compile' to turn a forging policy into a compiled Plutus Core program,
-- just as for validator scripts. We also provide a 'wrapMonetaryPolicy' function
-- to handle the boilerplate.
oneAtATimeCompiled :: CompiledCode PLC.DefaultUni (Data -> ())
oneAtATimeCompiled :: CompiledCode PLC.DefaultUni () (Data -> ())
oneAtATimeCompiled = $$(compile [|| wrapMonetaryPolicy oneAtATimePolicy ||])
-- BLOCK2
singleSignerPolicy :: PolicyCtx -> Bool
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorials/BasicValidators.hs
Expand Up @@ -39,7 +39,7 @@ alwaysFails _ _ _ = error ()

-- We can use 'compile' to turn a validator function into a compiled Plutus Core program.
-- Here's a reminder of how to do it.
alwaysSucceedsCompiled :: CompiledCode PLC.DefaultUni (Data -> Data -> Data -> ())
alwaysSucceedsCompiled :: CompiledCode PLC.DefaultUni () (Data -> Data -> Data -> ())
alwaysSucceedsCompiled = $$(compile [|| alwaysSucceeds ||])
-- BLOCK3
-- | Checks if a date is before the given end date.
Expand Down
22 changes: 11 additions & 11 deletions doc/tutorials/PlutusTx.hs
Expand Up @@ -26,9 +26,9 @@ import Language.PlutusTx.Prelude
-- >>> import Data.Text.Prettyprint.Doc

-- BLOCK2
integerOne :: CompiledCode PLC.DefaultUni Integer
integerOne :: CompiledCode PLC.DefaultUni () Integer
{- 'compile' turns the 'TExpQ Integer' into a
'TExpQ (CompiledCode PLC.DefaultUni Integer)' and the splice
'TExpQ (CompiledCode PLC.DefaultUni () Integer)' and the splice
inserts it into the program. -}
integerOne = $$(compile
{- The quote has type 'TExpQ Integer'.
Expand All @@ -43,7 +43,7 @@ integerOne = $$(compile
)
-}
-- BLOCK3
integerIdentity :: CompiledCode PLC.DefaultUni (Integer -> Integer)
integerIdentity :: CompiledCode PLC.DefaultUni () (Integer -> Integer)
integerIdentity = $$(compile [|| \(x:: Integer) -> x ||])

{- |
Expand Down Expand Up @@ -77,7 +77,7 @@ myProgram =
externalTwo = plusOne 1
in localTwo `addInteger` externalTwo

functions :: CompiledCode PLC.DefaultUni Integer
functions :: CompiledCode PLC.DefaultUni () Integer
functions = $$(compile [|| myProgram ||])

{- We’ve used the CK evaluator for Plutus Core to evaluate the program
Expand All @@ -87,7 +87,7 @@ functions = $$(compile [|| myProgram ||])
(con 4)
-}
-- BLOCK5
matchMaybe :: CompiledCode PLC.DefaultUni (Maybe Integer -> Integer)
matchMaybe :: CompiledCode PLC.DefaultUni () (Maybe Integer -> Integer)
matchMaybe = $$(compile [|| \(x:: Maybe Integer) -> case x of
Just n -> n
Nothing -> 0
Expand All @@ -97,29 +97,29 @@ matchMaybe = $$(compile [|| \(x:: Maybe Integer) -> case x of
data EndDate = Fixed Integer | Never

-- | Check whether a given time is past the end date.
pastEnd :: CompiledCode PLC.DefaultUni (EndDate -> Integer -> Bool)
pastEnd :: CompiledCode PLC.DefaultUni () (EndDate -> Integer -> Bool)
pastEnd = $$(compile [|| \(end::EndDate) (current::Integer) -> case end of
Fixed n -> n `lessThanEqInteger` current
Never -> False
||])
-- BLOCK7
-- | Check whether a given time is past the end date.
pastEnd' :: CompiledCode PLC.DefaultUni (EndDate -> Integer -> Bool)
pastEnd' :: CompiledCode PLC.DefaultUni () (EndDate -> Integer -> Bool)
pastEnd' = $$(compile [|| \(end::EndDate) (current::Integer) -> case end of
Fixed n -> n < current
Never -> False
||])
-- BLOCK8
addOne :: CompiledCode PLC.DefaultUni (Integer -> Integer)
addOne :: CompiledCode PLC.DefaultUni () (Integer -> Integer)
addOne = $$(compile [|| \(x:: Integer) -> x `addInteger` 1 ||])
-- BLOCK9
addOneToN :: Integer -> CompiledCode PLC.DefaultUni Integer
addOneToN :: Integer -> CompiledCode PLC.DefaultUni () Integer
addOneToN n =
addOne
-- 'applyCode' applies one 'CompiledCode' to another.
`applyCode`
-- 'liftCode' lifts the argument 'n' into a
-- 'CompiledCode PLC.DefaultUni Integer'.
-- 'CompiledCode PLC.DefaultUni () Integer'.
liftCode n

{- |
Expand Down Expand Up @@ -164,7 +164,7 @@ addOneToN n =
-- 'makeLift' generates instances of 'Lift' automatically.
makeLift ''EndDate

pastEndAt :: EndDate -> Integer -> CompiledCode PLC.DefaultUni Bool
pastEndAt :: EndDate -> Integer -> CompiledCode PLC.DefaultUni () Bool
pastEndAt end current =
pastEnd
`applyCode`
Expand Down
6 changes: 3 additions & 3 deletions doc/tutorials/plutus-tx.rst
Expand Up @@ -60,12 +60,12 @@ The Plutus Tx compiler compiles Haskell *expressions* (not values!), so
naturally it takes a quote (representing an expression) as an argument.
The result is a new quote, this time for a Haskell program that
represents the *compiled* program. In Haskell, the type of :hsobj:`Language.PlutusTx.TH.compile`
is ``TExpQ a → TExpQ (CompiledCode PLC.DefaultUni a)``. This is just
is ``TExpQ a → TExpQ (CompiledCode PLC.DefaultUni () a)``. This is just
what we already said:

- ``TExpQ a`` is a quoted representing a program of type ``a``.

- ``TExprQ (CompiledCode PLC.DefaultUni a)`` is quote representing a
- ``TExprQ (CompiledCode PLC.DefaultUni () a)`` is quote representing a
compiled Plutus Core program.

.. note::
Expand Down Expand Up @@ -103,7 +103,7 @@ This simple program just evaluates to the integer ``1``.
:end-before: BLOCK3

We can see how the metaprogramming works: the Haskell program ``1``
was turned into a ``CompiledCode PLC.DefaultUni Integer`` at compile
was turned into a ``CompiledCode PLC.DefaultUni () Integer`` at compile
time, which we spliced into our Haskell program. We can inspect at runtime
to see the generated Plutus Core (or to put it on the blockchain).

Expand Down

0 comments on commit 470f4fe

Please sign in to comment.