Commit 411a2ab0 authored by Kim Nguyễn's avatar Kim Nguyễn
Browse files

re-organise the test files and add new typing tests.

parent 9d34f8a7
let pretty (x : Int) : String = string_of x
;;
let pretty (x : Int) : String = string_of x;;
let even (Int -> Bool; ('a\Int) -> ('a\Int)) let even (Int -> Bool; ('a\Int) -> ('a\Int))
| x & Int -> (x mod 2) = 0 | x & Int -> (x mod 2) = 0
| x -> x | x -> x
;; ;;
let mmap (f : 'a -> 'b) (l : [ ('a) *] ) : [ ('b) *] = let mmap (f : 'a -> 'b) (l : [ ('a) *] ) : [ ('b) *] =
match l with match l with
[] -> [] [] -> []
| (e, ll) -> (f e, mmap f ll) | (e, ll) -> (f e, mmap f ll)
;; ;;
let map_even = mmap even let map_even = mmap even
;; ;;
let g ( (Int -> Int) -> Int -> Int; let g ( (Int -> Int) -> Int -> Int;
(Bool -> Bool) -> Bool -> Bool) x -> x (Bool -> Bool) -> Bool -> Bool) x -> x
;; ;;
let id ('a -> 'a) x -> x;; let id ('a -> 'a) x -> x;;
let gid = g id;; let gid = g id;;
let id2g = id (id g);; let id2g = id (id g);;
let churchtrue (x : 'a) (y : 'b) : 'a = x in churchtrue 42;; let churchtrue (x : 'a) (_ : 'b) : 'a = x in churchtrue 42;;
let max (x : 'a) (y : 'a) : 'a = if x >> y then x else y;; let max (x : 'a) (y : 'a) : 'a = if x >> y then x else y;;
...@@ -40,20 +45,21 @@ let apply_to_3 (f: Int -> 'a): 'a = f 3 in ...@@ -40,20 +45,21 @@ let apply_to_3 (f: Int -> 'a): 'a = f 3 in
mmap apply_to_3 twisted mmap apply_to_3 twisted
;; ;;
type A('a) = <a>'a type A('a) = <a>('a)
type B('a) = <b>[(A('a)|B('a))];; type B('a) = <b>[(A('a)|B('a))];;
let f (_ : 'a -> 'a -> 'a)(z : 'a)(_ : A('a)|B('a)) : A('a) = <a>z;; let f (_ : 'a -> 'a -> 'a)(z : 'a)(_ : A('a)|B('a)) : A('a) = <a>z;;
let sum (x : Int) (y : Int) : Int = x + y;;
let x = f sum;;
let sum (x : Int) (y : Int) : Int = x + y;;
(* Some expressions that are ill typed *) let x = f sum;;
let id ('a -> 'a) let f ( x : B('a) ) : 'a =
Int -> "foo" match x with
| x -> x <b>[ <a>i ] -> i
;; |<b>[ y ] -> f y
let apply ( f : 'a -> 'b) (x : 'a ) : 'b =
f (x,x)
;; ;;
let v = f <b>[<b>[<a>32]]
;;
\ No newline at end of file
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