6 changed files with 168 additions and 8 deletions
@ -1,10 +1,20 @@ |
|||
import java.util.ArrayList; |
|||
import java.util.AbstractMap.SimpleEntry; |
|||
|
|||
public class main { |
|||
public class layout { |
|||
public static void main(String[] args) { |
|||
int[] array1 = [ 1, 2, 3 ]; |
|||
ArrayList<T> array2 = new ArrayList([ 42, 99, 666 ]); |
|||
Pair<ArrayList<T>> pair = new Pair(array1, array2); |
|||
int[] array1 = { 1, 2, 3 }; |
|||
ArrayList<Integer> array2 = new ArrayList<Integer>(); |
|||
array2.add(42); |
|||
array2.add(99); |
|||
array2.add(666); |
|||
SimpleEntry<ArrayList<Integer>, ArrayList<Integer>> pair = |
|||
new SimpleEntry<ArrayList<Integer>, ArrayList<Integer>>( |
|||
new ArrayList<Integer>(), |
|||
array2); |
|||
pair.getKey().add(1); |
|||
pair.getKey().add(2); |
|||
pair.getKey().add(3); |
|||
int x = 42; |
|||
} |
|||
} |
|||
|
@ -0,0 +1,37 @@ |
|||
(module |
|||
|
|||
(type $t1 (array (mut i32))) |
|||
(type $t2 (array (mut (ref i31)))) |
|||
(type $tpair (struct |
|||
(field $left (ref $t1)) |
|||
(field $right (ref $t2)))) |
|||
|
|||
(func $f |
|||
(local $array1 (ref $t1)) (local $array2 (ref $t2)) |
|||
(local $pair (ref $tpair)) (local $x i32) |
|||
|
|||
(array.new_canon $t1 (i32.const 0) (i32.const 3)) |
|||
(local.set $array1) |
|||
(array.set $t1 (local.get $array1) (i32.const 0) (i32.const 1)) |
|||
(array.set $t1 (local.get $array1) (i32.const 1) (i32.const 2)) |
|||
(array.set $t1 (local.get $array1) (i32.const 2) (i32.const 3)) |
|||
|
|||
(array.new_canon $t2 (i31.new (i32.const 0)) (i32.const 3)) |
|||
(local.set $array2) |
|||
(array.set $t2 (local.get $array2) (i32.const 0) |
|||
(i31.new (i32.const 42))) |
|||
(array.set $t2 (local.get $array2) (i32.const 1) |
|||
(i31.new (i32.const 99))) |
|||
(array.set $t2 (local.get $array2) (i32.const 2) |
|||
(i31.new (i32.const 666))) |
|||
|
|||
(struct.new_canon $tpair |
|||
(local.get $array1) (local.get $array2)) |
|||
(local.set $pair) |
|||
|
|||
(i32.const 42) |
|||
(local.set $x) |
|||
) |
|||
|
|||
(start $f) |
|||
) |
@ -0,0 +1,26 @@ |
|||
type ral<'a> = |
|||
| Nil |
|||
| Zero of ral<'a * 'a> |
|||
| One of 'a * ral<'a * 'a> |
|||
|
|||
let rec length<'a> (l : ral<'a>) : int = |
|||
match l with |
|||
| Nil -> 0 |
|||
| Zero s -> 2 * length s |
|||
| One (_v, s) -> 1 + 2 * length s |
|||
|
|||
let rec cons<'a> (x : 'a) (l : ral<'a>) : ral<'a> = |
|||
match l with |
|||
| Nil -> One (x, Nil) |
|||
| Zero s -> One (x, s) |
|||
| One (y, s) -> Zero (cons (x, y) s) |
|||
|
|||
let rec loop l = |
|||
let len = length l |
|||
if len < 3000000 then |
|||
let l = cons 42 l |
|||
printfn "len = %d" (length l) |
|||
loop l |
|||
|
|||
loop Nil |
|||
loop Nil |
Loading…
Reference in new issue