Liquid types
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
|
||||
|
||||
contract C =
|
||||
stateful entrypoint f(a, x:int) =
|
||||
if(a < x) a else x
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
contract C =
|
||||
entrypoint fff() = 123
|
||||
|
||||
function
|
||||
f : {n : int | n > 0} => {res : int | res =< n}
|
||||
f(x) =
|
||||
switch(x)
|
||||
_ => 1 / x
|
||||
@@ -0,0 +1,9 @@
|
||||
contract C =
|
||||
entrypoint f1() =
|
||||
1 / (Contract.balance + 2)
|
||||
|
||||
stateful entrypoint f2(a) =
|
||||
require(Contract.balance > 11, "")
|
||||
Chain.spend(a, 10)
|
||||
1 / Contract.balance
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
contract C =
|
||||
entrypoint f() = 1 / 0
|
||||
|
||||
entrypoint g(x) = 1 / x
|
||||
|
||||
stateful entrypoint h(a, x) = Chain.spend(a, x)
|
||||
|
||||
entrypoint i(x) =
|
||||
switch(x)
|
||||
0 => 1
|
||||
|
||||
entrypoint j(x) =
|
||||
switch(x)
|
||||
_ => 1
|
||||
_ => 2
|
||||
|
||||
entrypoint k(x) =
|
||||
let 0 = x
|
||||
x
|
||||
|
||||
entrypoint
|
||||
l : () => {n : int | n > 0}
|
||||
l() = 0
|
||||
@@ -0,0 +1,5 @@
|
||||
contract C =
|
||||
entrypoint
|
||||
len : {l : list('a)} => {r : int | r == l}
|
||||
len([]) = 0
|
||||
len(_::t) = len(t)
|
||||
@@ -0,0 +1,6 @@
|
||||
contract C =
|
||||
entrypoint max(a : int, b : int) =
|
||||
if(a >= b) a else b
|
||||
|
||||
entrypoint trim(x) =
|
||||
max(0, x)
|
||||
@@ -0,0 +1,9 @@
|
||||
contract C =
|
||||
stateful entrypoint f1(a) =
|
||||
require(Contract.balance == 10, "xd")
|
||||
Chain.spend(a, 10)
|
||||
Contract.balance
|
||||
|
||||
entrypoint f2(x) =
|
||||
require(x > 0, "")
|
||||
1 / x
|
||||
@@ -0,0 +1,15 @@
|
||||
include "List.aes"
|
||||
|
||||
contract C =
|
||||
payable stateful entrypoint split(targets : list(address)) =
|
||||
require(targets != [], "NO_TARGETS")
|
||||
let value_per_person = Call.value / List.length(targets)
|
||||
spend_to_all(value_per_person, targets)
|
||||
|
||||
stateful function
|
||||
spend_to_all : ({v : int | v >= 0}, list(address)) => unit
|
||||
spend_to_all(_, []) = ()
|
||||
spend_to_all(value, addr::rest) =
|
||||
require(value < Contract.balance, "")
|
||||
Chain.spend(addr, value)
|
||||
spend_to_all(value, rest)
|
||||
@@ -0,0 +1,7 @@
|
||||
contract C =
|
||||
record state = {x : int}
|
||||
|
||||
function inc(x) = x + 1
|
||||
stateful entrypoint f() =
|
||||
let s = state
|
||||
state.x
|
||||
@@ -0,0 +1,12 @@
|
||||
contract C =
|
||||
entrypoint f(x) =
|
||||
switch(x)
|
||||
1 => x
|
||||
2 => 2
|
||||
y => (x + y) / 2
|
||||
|
||||
function
|
||||
g : {n : int | n > 0 && n < 4} => {r : int | r == 2}
|
||||
g(1) = 2
|
||||
g(2) = 2
|
||||
g(3) = g(1) + 0
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
include "List.aes"
|
||||
|
||||
contract Test =
|
||||
stateful entrypoint f(l, a) =
|
||||
require(Contract.balance > 10, "xd")
|
||||
Chain.spend(l, 10)
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
contract C =
|
||||
type i('a) = 'a
|
||||
type ii = i(int)
|
||||
datatype iii = III(ii)
|
||||
datatype ib = I(i(int)) | B(bool) | IB(int, bool)
|
||||
datatype d_nest = DNest(ib)
|
||||
|
||||
datatype maybe('a) = Nothing | Just('a)
|
||||
|
||||
type maybemaybe('a) = maybe(maybe('a))
|
||||
type maybe_int = maybe(int)
|
||||
|
||||
record r = {i : int, b : bool}
|
||||
record rr = {r : r}
|
||||
|
||||
entrypoint
|
||||
test_i : () => {res : int | res == 123}
|
||||
test_i() = 123
|
||||
|
||||
entrypoint
|
||||
test_ii : (ii) => {res : int | res == 123}
|
||||
test_ii(x) = x - x + 123
|
||||
|
||||
entrypoint
|
||||
test_iii1() = III(123)
|
||||
entrypoint
|
||||
test_iii2 : () => {iii <: III({res : int | res > 0})}
|
||||
test_iii2() = III(123)
|
||||
/*
|
||||
entrypoint
|
||||
test_ib1() = I(1)
|
||||
entrypoint
|
||||
test_ib2() = B(true)
|
||||
entrypoint
|
||||
test_ib3() = IB(123, true)
|
||||
function
|
||||
test_ib4 : {ib <: I({n : int | n == 0})} => {res : int | res == 1}
|
||||
test_ib4(I(0)) = 1
|
||||
function
|
||||
test_ib5 : {ib <: I({n : int | n == 0})} => {res : int | res == 1}
|
||||
test_ib5(q) = switch(q)
|
||||
_ => 1
|
||||
function
|
||||
test_ib6 : bool => {ib <: IB({n : int | n == 0}, bool)}
|
||||
test_ib6(b) = IB(0, b)
|
||||
|
||||
entrypoint test_maybemaybe() = Just(Nothing)
|
||||
|
||||
entrypoint test_maybe_int() = Nothing
|
||||
*/
|
||||
Reference in New Issue
Block a user