Script Constructor
module Refer where
import Daml.Script
import DA.Time
import DA.Date
native_test : Script ()
native_test = script do
alice ← allocateParty “Alice”
bob ← allocateParty “Bob”
let
my_int = -123
my_dec = 0.001 : Decimal
my_text = “Alice”
my_bool = False
my_date = date 2020 Jan 01
my_time = time my_date 00 00 00
my_rel_time = hours 24
assert (-my_int == 123)
assert (1000.0 * my_dec == 1.0)
assert (my_text == “Alice”)
assert (not my_bool)
assert (addDays my_date 1 == date 2020 Jan 02)
assert (addRelTime my_time my_rel_time == time (addDays my_date 1) 00 00 00)
Is below the way to trigger above script, if not plz correct my understanding.
daml script --dar .daml/dist/create-daml-app-0.1.0.dar --script-name Refer:native_test --ledger-host localhost --ledger-port 6865
Also,
what is the purpose of having constructor first and then script with do keyword.
Yes, that is the correct invocation.
What do you call “constructor” in this case?
@kanika_kapoor, perhaps some explanation of these two lines would be helpful?
native_test : Script ()
native_test = script do
:
- The line
native_test : Script ()declares the type of the “variable” namednative_test. - The line
native_test = script dobegins the binding of a value to that variable.
A similar example could be the following:
x : Int
x = 3
You could alternatively do this:
x : Int = 3
native_test : Script () = script do
:
And in many cases you can leave out the type declaration and the compiler will infer the type.
x = 3
native_test = script do
:
And in many cases you can leave out the type declaration and the compiler will infer the type.
I would strongly advise you to never leave out the type for top-level declarations.