Commit ebbc1761 authored by Pinto Pasquale's avatar Pinto Pasquale Committed by Ivan Gromakovskii

[#90] fix Indigo's tutorial package to make it buildable

Problem: Indigo's tutorial does not actually build, because its
example modules are not included in the cabal file.
This was caused by the modules having thir name starting with a
number instead of a capital letter.
Additionally, recent updates have broken these modules so they
would not compile anyway.

Solution: rename modules to include them in the cabal file, fix what
was broken by recent changes.
parent 647cc5ad
Pipeline #133695597 passed with stages
in 9 minutes and 51 seconds
......@@ -38,6 +38,7 @@ module Indigo.Frontend.Language
-- * Scope
, scope
, defFunction
, defContract
-- * Loop
, while
......@@ -73,7 +74,6 @@ module Indigo.Frontend.Language
-- * Blocks
, IndigoFunction
, IndigoProcedure
, IndigoContractCode
, IndigoEntrypoint
-- * Helpers
......@@ -364,11 +364,6 @@ type IndigoFunction ret = IndigoM (ScopeRetVars ret)
-- values in it) and returns nothing.
type IndigoProcedure = IndigoM ()
type IndigoContractCode param store =
(HasStorage store, HasSideEffects)
=> Var param
-> IndigoProcedure
type IndigoEntrypoint param = param -> IndigoProcedure
scope
......@@ -377,13 +372,21 @@ scope
-> IndigoFunction a
scope = oneIndigoM . Scope
-- | Alias for `scope` we use in a tutorial.
-- | Alias for `scope` we use in the tutorial.
defFunction
:: forall a . ScopeCodeGen a
=> IndigoM a
-> IndigoFunction a
defFunction = scope
-- | A more specific version of 'defFunction' meant to more easily create
-- 'IndigoContract's. Used in the tutorial. The 'HasSideEffects' constraint is
-- specified to avoid the warning for redundant constraints.
defContract
:: (HasSideEffects => IndigoM ())
-> (HasSideEffects => IndigoProcedure)
defContract = scope
----------------------------------------------------------------------------
-- Loop
----------------------------------------------------------------------------
......
......@@ -5,11 +5,11 @@ It aims to be accessible to as many people as possible, but also contains more
technical information for Haskell developers that are interested in learning more.
## Tutorial index
- [00 - Getting started](src/Indigo/Tutorial/00)
- [01 - Basics and Variables](src/Indigo/Tutorial/01)
- [02 - Expressions and operators](src/Indigo/Tutorial/02)
- [03 - Imperative statements](src/Indigo/Tutorial/03)
- [04 - Functions and Procedures](src/Indigo/Tutorial/04)
- [05 - Side Effects and Errors](src/Indigo/Tutorial/05)
- [00 - Getting started](src/Indigo/Tutorial/T00)
- [01 - Basics and Variables](src/Indigo/Tutorial/T01)
- [02 - Expressions and operators](src/Indigo/Tutorial/T02)
- [03 - Imperative statements](src/Indigo/Tutorial/T03)
- [04 - Functions and Procedures](src/Indigo/Tutorial/T04)
- [05 - Side Effects and Errors](src/Indigo/Tutorial/T05)
- [Appendix A: types](src/Indigo/Tutorial/AA.md)
- [Appendix B: expressions](src/Indigo/Tutorial/AB.md)
......@@ -4,7 +4,7 @@ cabal-version: 2.2
--
-- see: https://github.com/sol/hpack
--
-- hash: 9d191454ebdf78b3a44fa68cc18f2237e285b9c28b5948feb83c9314ae26f4a7
-- hash: d8bdaac0ba6e273d6a3894aaed6dfc5236ca44f4acb74765b37cc1601e3ea5c1
name: indigo-tutorial
version: 0.1.0.0
......@@ -21,12 +21,12 @@ license-file: LICENSE
build-type: Simple
extra-source-files:
README.md
src/Indigo/Tutorial/00/index.md
src/Indigo/Tutorial/01/index.md
src/Indigo/Tutorial/02/index.md
src/Indigo/Tutorial/03/index.md
src/Indigo/Tutorial/04/index.md
src/Indigo/Tutorial/05/index.md
src/Indigo/Tutorial/T00/index.md
src/Indigo/Tutorial/T01/index.md
src/Indigo/Tutorial/T02/index.md
src/Indigo/Tutorial/T03/index.md
src/Indigo/Tutorial/T04/index.md
src/Indigo/Tutorial/T05/index.md
src/Indigo/Tutorial/AA.md
src/Indigo/Tutorial/AB.md
......@@ -35,6 +35,14 @@ source-repository head
location: [email protected]:morley-framework/morley.git
library
exposed-modules:
Indigo.Tutorial.T00.Example
Indigo.Tutorial.T01.Example
Indigo.Tutorial.T02.Math
Indigo.Tutorial.T03.Control
Indigo.Tutorial.T04.Functions
Indigo.Tutorial.T05.Errors
Indigo.Tutorial.T05.SideEffects
other-modules:
Paths_indigo_tutorial
autogen-modules:
......
......@@ -10,12 +10,12 @@ description: Tutorial for Indigo eDSL.
category: Language
extra-source-files:
- README.md
- src/Indigo/Tutorial/00/index.md
- src/Indigo/Tutorial/01/index.md
- src/Indigo/Tutorial/02/index.md
- src/Indigo/Tutorial/03/index.md
- src/Indigo/Tutorial/04/index.md
- src/Indigo/Tutorial/05/index.md
- src/Indigo/Tutorial/T00/index.md
- src/Indigo/Tutorial/T01/index.md
- src/Indigo/Tutorial/T02/index.md
- src/Indigo/Tutorial/T03/index.md
- src/Indigo/Tutorial/T04/index.md
- src/Indigo/Tutorial/T05/index.md
- src/Indigo/Tutorial/AA.md
- src/Indigo/Tutorial/AB.md
......
## Tutorial index
- [00 - Getting started](00)
- [01 - Basics and Variables](01)
- [02 - Expressions and operators](02)
- [03 - Imperative statements](03)
- [04 - Functions and Procedures](04)
- [05 - Side Effects and Errors](05)
- [00 - Getting started](T00)
- [01 - Basics and Variables](T01)
- [02 - Expressions and operators](T02)
- [03 - Imperative statements](T03)
- [04 - Functions and Procedures](T04)
- [05 - Side Effects and Errors](T05)
- **Appendix A: types**
- [Appendix B: expressions](AB.md)
......
## Tutorial index
- [00 - Getting started](00)
- [01 - Basics and Variables](01)
- [02 - Expressions and operators](02)
- [03 - Imperative statements](03)
- [04 - Functions and Procedures](04)
- [05 - Side Effects and Errors](05)
- [00 - Getting started](T00)
- [01 - Basics and Variables](T01)
- [02 - Expressions and operators](T02)
- [03 - Imperative statements](T03)
- [04 - Functions and Procedures](T04)
- [05 - Side Effects and Errors](T05)
- [Appendix A: types](AA.md)
- **Appendix B: expressions**
......
module Indigo.Tutorial.00.Example
module Indigo.Tutorial.T00.Example
( exampleContract
) where
......
## Tutorial index
- **00 - Getting started**
- [01 - Basics and Variables](../01)
- [02 - Expressions and operators](../02)
- [03 - Imperative statements](../03)
- [04 - Functions and Procedures](../04)
- [05 - Side Effects and Errors](../05)
- [01 - Basics and Variables](../T01)
- [02 - Expressions and operators](../T02)
- [03 - Imperative statements](../T03)
- [04 - Functions and Procedures](../T04)
- [05 - Side Effects and Errors](../T05)
- [Appendix A: types](../AA.md)
- [Appendix B: expressions](../AB.md)
......@@ -45,7 +45,7 @@ will get faster later on, I promise.
You can now load a source file by using the `:load` command, we can start by
loading the example code provided in this chapter by using:
```bash
:load code/indigo/tutorial/00/Example.hs
:load code/indigo/tutorial/T00/Example.hs
```
Note: for these examples, you may receive warnings about `missing-home-modules`,
you can safely ignore these.
......@@ -72,7 +72,7 @@ With these tools at your disposal you will be able to create Indigo contracts an
compile them to Michelson, just by using the REPL.
If you are ready for it, you should head straight for the next chapter:
[Basics and Variables](../01).
[Basics and Variables](../T01).
### Technical details: developing using Indigo
......
module Indigo.Tutorial.01.Example
module Indigo.Tutorial.T01.Example
( exampleContract
, textKeeper
) where
......
## Tutorial index
- [00 - Getting started](../00)
- [00 - Getting started](../T00)
- **01 - Basics and Variables**
- [02 - Expressions and operators](../02)
- [03 - Imperative statements](../03)
- [04 - Functions and Procedures](../04)
- [05 - Side Effects and Errors](../05)
- [02 - Expressions and operators](../T02)
- [03 - Imperative statements](../T03)
- [04 - Functions and Procedures](../T04)
- [05 - Side Effects and Errors](../T05)
- [Appendix A: types](../AA.md)
- [Appendix B: expressions](../AB.md)
......@@ -102,7 +102,7 @@ that also explains how to create your own types from scratch.
On the other end you are probably curious about what are the expressions and
operators available in Indigo beside `+.`.
If this is the case you are in luck, because it is exactly the topic of the
[next chapter](../02)!
[next chapter](../T02)!
### Technical details: IndigoState and Var
......
module Indigo.Tutorial.02.Math
module Indigo.Tutorial.T02.Math
( mathContract
) where
......
## Tutorial index
- [00 - Getting started](../00)
- [01 - Basics and Variables](../01)
- [00 - Getting started](../T00)
- [01 - Basics and Variables](../T01)
- **02 - Expressions and operators**
- [03 - Imperative statements](../03)
- [04 - Functions and Procedures](../04)
- [05 - Side Effects and Errors](../05)
- [03 - Imperative statements](../T03)
- [04 - Functions and Procedures](../T04)
- [05 - Side Effects and Errors](../T05)
- [Appendix A: types](../AA.md)
- [Appendix B: expressions](../AB.md)
......@@ -67,7 +67,7 @@ where `storage_type` is the only thing to fill and has to match the one from
the contract we are using this `storage` in.
Although we now know how to compose operators, expressions, variables, etc. we
still only have linear code execution, hence the next chapter: [Imperative statements](../03)
still only have linear code execution, hence the next chapter: [Imperative statements](../T03)
### Technical details: expressions evaluation and variables
......
module Indigo.Tutorial.03.Control
module Indigo.Tutorial.T03.Control
( controlContract
) where
......
## Tutorial index
- [00 - Getting started](../00)
- [01 - Basics and Variables](../01)
- [02 - Expressions and operators](../02)
- [00 - Getting started](../T00)
- [01 - Basics and Variables](../T01)
- [02 - Expressions and operators](../T02)
- **03 - Imperative statements**
- [04 - Functions and Procedures](../04)
- [05 - Side Effects and Errors](../05)
- [04 - Functions and Procedures](../T04)
- [05 - Side Effects and Errors](../T05)
- [Appendix A: types](../AA.md)
- [Appendix B: expressions](../AB.md)
......@@ -109,7 +109,7 @@ This contract is a bit bigger than usual and not much readable as-is, moreover,
the situation would get worse if we kept adding to it, especially if there are
repeated blocks of code.
For this reason Indigo supports functions and procedures, which are the
argument of [the next chapter](../04).
argument of [the next chapter](../T04).
### Technical details: Imperative statements and scopes
......
module Indigo.Tutorial.04.Functions
module Indigo.Tutorial.T04.Functions
( functionsContract
) where
......@@ -21,11 +21,11 @@ functionsContract param = defContract $ do
)
updateStorage result
checkZero :: Var Integer -> IndigoFunction s Bool
checkZero :: Var Integer -> IndigoFunction Bool
checkZero val = defFunction $ do
return (val ==. (0 :: Integer))
checkHasDigitOne :: Var Natural -> IndigoFunction s Bool
checkHasDigitOne :: Var Natural -> IndigoFunction Bool
checkHasDigitOne val = defFunction $ do
base <- newVar @Natural 10
checkRes <- newVar False
......@@ -35,11 +35,11 @@ checkHasDigitOne val = defFunction $ do
setVar checkRes (remainder ==. (1 :: Natural))
return checkRes
updateStorage :: HasStorage Natural => Var Bool -> IndigoProcedure s
updateStorage :: HasStorage Natural => Var Bool -> IndigoProcedure
updateStorage result = defFunction $ do
if result then setVar storage (0 :: Natural) else incrementStorage
incrementStorage :: HasStorage Natural => IndigoProcedure s
incrementStorage :: HasStorage Natural => IndigoProcedure
incrementStorage = defFunction $ do
storage += (1 :: Natural)
......
## Tutorial index
- [00 - Getting started](../00)
- [01 - Basics and Variables](../01)
- [02 - Expressions and operators](../02)
- [03 - Imperative statements](../03)
- [00 - Getting started](../T00)
- [01 - Basics and Variables](../T01)
- [02 - Expressions and operators](../T02)
- [03 - Imperative statements](../T03)
- **04 - Functions and Procedures**
- [05 - Side Effects and Errors](../05)
- [05 - Side Effects and Errors](../T05)
- [Appendix A: types](../AA.md)
- [Appendix B: expressions](../AB.md)
......@@ -25,7 +25,7 @@ read because it has been broken down into simple functions.
Let's look at their definition, starting from the first one:
```haskell
checkZero :: Var Integer -> IndigoFunction s Bool
checkZero :: Var Integer -> IndigoFunction Bool
checkZero val = defFunction $ do
return (val ==. (0 :: Integer))
```
......@@ -50,17 +50,15 @@ checkZero val = defFunction $ do
The other difference is that by using functions we need to explicitly write a
signature, but this is not hard, we can see that the ones for `checkZero` is:
```haskell
checkZero :: Var Integer -> IndigoFunction s Bool
checkZero :: Var Integer -> IndigoFunction Bool
```
Just as we did in the [Basics and Variables](../01) chapter for contracts,
Just as we did in the [Basics and Variables](../T01) chapter for contracts,
we can use a formula to make function signatures:
```
<function_name> :: [Var parameter ->] IndigoFunction <stack_type> <return_type>
<function_name> :: [Var parameter ->] IndigoFunction <return_type>
```
Here's what you need to know:
- there can be 0 parameters as well as more than one.
- the stack type restricts what the stack needs to look like when the function is
called, if you leave it to `s` the compiler will try to derive it for you.
- The return type can be any of the supported types.
In addition to this there are `IndigoProcedure`s, that are just like
......@@ -79,7 +77,7 @@ note that just like the other imperative constructs they have (automatically
managed) scope.
Now that we are armed with functions as well we can proceed to the final chapter:
[Side Effects and Errors](../05).
[Side Effects and Errors](../T05).
### Technical details: defFunction and defContract
......
module Indigo.Tutorial.05.Errors
module Indigo.Tutorial.T05.Errors
( errorsContract
) where
......@@ -21,11 +21,11 @@ errorsContract param = defContract $ do
)
incrementStorage
checkZero :: Var Integer -> IndigoProcedure s
checkZero :: Var Integer -> IndigoProcedure
checkZero val = defFunction $ do
assert [mt|unacceptable zero value|] (val ==. (0 :: Integer))
checkHasDigitOne :: Var Natural -> IndigoProcedure s
checkHasDigitOne :: Var Natural -> IndigoProcedure
checkHasDigitOne val = defFunction $ do
base <- newVar @Natural 10
while (val >. base) $ do
......@@ -34,11 +34,11 @@ checkHasDigitOne val = defFunction $ do
checkSingleDigitOne remainder
checkSingleDigitOne val
checkSingleDigitOne :: Var Natural -> IndigoProcedure s
checkSingleDigitOne :: Var Natural -> IndigoProcedure
checkSingleDigitOne digit = do
assert [mt|unacceptable non-one digit|] (digit ==. (1 :: Natural))
incrementStorage :: HasStorage Natural => IndigoProcedure s
incrementStorage :: HasStorage Natural => IndigoProcedure
incrementStorage = defFunction $ do
storage += (1 :: Natural)
......
module Indigo.Tutorial.05.SideEffects
module Indigo.Tutorial.T05.SideEffects
( sideEffectsContract
, textKeeper
) where
......@@ -18,15 +18,15 @@ textKeeper :: IndigoContract MText MText
textKeeper param = defContract $ do
setVar storageVar param
initializeContract :: HasSideEffects => Var Address -> Var MText -> IndigoProcedure s
initializeContract :: HasSideEffects => Var Address -> Var MText -> IndigoProcedure
initializeContract addr msg = defFunction $ do
mtz <- newVar (toMutez 0)
ifJust (contract addr)
(\cRef -> transferTokens msg mtz cRef)
failForRef
failForRef :: IndigoProcedure s
failForRef = failUsing_ [mt|failed to create contract reference|]
failForRef :: IndigoProcedure
failForRef = failUnexpected_ [mt|failed to create contract reference|]
storage :: HasStorage Address => Var Address
storage = storageVar
## Tutorial index
- [00 - Getting started](../00)
- [01 - Basics and Variables](../01)
- [02 - Expressions and operators](../02)
- [03 - Imperative statements](../03)
- [04 - Functions and Procedures](../04)
- [00 - Getting started](../T00)
- [01 - Basics and Variables](../T01)
- [02 - Expressions and operators](../T02)
- [03 - Imperative statements](../T03)
- [04 - Functions and Procedures](../T04)
- **05 - Side Effects and Errors**
- [Appendix A: types](../AA.md)
- [Appendix B: expressions](../AB.md)
......@@ -16,7 +16,7 @@ Indigo supports side-effects and errors to handle these needs, respectively.
### Failing instead
In the contract from the [previous chapter](../04) we performed a check, based
In the contract from the [previous chapter](../T04) we performed a check, based
on the parameter of the contract, and modified the `storage` depending on the
result of said check.
......@@ -58,12 +58,16 @@ Apart from the `assert` that we show here, Indigo also supports this constructs
for failing:
- `failWith` that has one argument: an expression for any type, this is the
same behavior as Michelson's `FAILWITH`
- `failUsing_` that has one argument: an expression for an error message, just
like `assert` (it is in fact how this is implemented)
- `failCustom` that expects a `Label` and an error message to compose a custom
failure value
- `failCustom_` that has only one `Label` argument, and is a specialization of
the previous one
- `failUnexpected_` that has one argument: an expression for an error message,
just like `assert`
- `assertCustom` that works just like `assert`, but with the same inputs as
`failCustom`
- `assertCustom_` that works just like `assert`, but with the same input as
`failCustom_`
### Side Effects
......@@ -100,7 +104,7 @@ side effects require the constraint `HasSideEffects` to be specified.
If you need a function that does both, remember that you can do so by using
the syntax in this formula:
```haskell
<function_name> :: (HasStorage <storage_type>, HasSideEffects) => IndigoFunction s <return_type>
<function_name> :: (HasStorage <storage_type>, HasSideEffects) => IndigoFunction <return_type>
```
If you followed up to this point this contract should not be confusing, remember
......
......@@ -570,7 +570,7 @@ managedLedgerContract = compileIndigoContract managedLedgerIndigo
storage :: HasStorage Storage => Var Storage
storage = storageVar
managedLedgerIndigo :: IndigoContractCode Parameter Storage
managedLedgerIndigo :: IndigoContract Parameter Storage
managedLedgerIndigo param = contractName "Managed Ledger" $ do
contractGeneralDefault
doc $ DDescription contractDoc
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment