-
Notifications
You must be signed in to change notification settings - Fork 0
/
listaCompras.aes
48 lines (35 loc) · 991 Bytes
/
listaCompras.aes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
ejercicio crear un contrato para manejar una lista de compras
cada item debe contener
codigo (texto)
nombre (texto)
cantidad (int)
precio (int)
la lista de compras maneja una lista de items, una cantidad total y un total
subirlo a github en un repositorio publico y agregar omar-saadoun como colaborador
contract buyingList
*/
contract listaCompras =
type item = {
codigo : String,
nombre : String,
cantidad : int,
precio : int
}
record listaItems = {
items: list(item)
}
function largo(xs) =
switch(xs)
[] => 0
_ :: xs => largo(xs) + 1
function cantidadTotal(xs) : int
switch(xs)
[] => 0
head.Cantidad::tail => head.Cantidad + cantidadTotal(tail)
function total(xs) : int
switch(xs)
[] => 0
head.precio::tail => head.precio + total(tail)
cantidadTotal(listaItems.items)
total(listaItems.items)