Commit ae786716 authored by Kim Nguyễn's avatar Kim Nguyễn

Preliminary work on pretty-printing of types. Try to split a type as a union

of sequence|non_variable|(toplevelvar ^ rest)
with special cases when non_variable or sequence are empty and toplevelvar or rest are any
(or any combination of thoses).

Add the examples of the part2 paper in a test file.
parent 7f7b54c8
let pretty (x : Int) : String = string_of x;;
let even (Int -> Bool; ('a\Int) -> ('a\Int))
| x & Int -> (x mod 2) = 0
| x -> x
;;
let mmap (f : 'a -> 'b) (l : [ ('a) *] ) : [ ('b) *] =
match l with
[] -> []
| (e, ll) -> (f e, mmap f ll)
;;
let map_even = mmap even
;;
let g ( (Int -> Int) -> Int -> Int;
(Bool -> Bool) -> Bool -> Bool) x -> x
;;
let id ('a -> 'a) x -> x;;
let gid = g id;;
let id2g = id (id g);;
let churchtrue (x : 'a) (y : 'b) : 'a = x in churchtrue 42;;
let max (x : 'a) (y : 'a) : 'a = if x >> y then x else y;;
max 42;;
type RBtree = Btree | Rtree
type Btree = <blk elem='a>[ RBtree RBtree ] | []
type Rtree = <red elem='a>[ Btree Btree ]
type Unbal = <blk elem='a>( [ Wrong RBtree ]
| [ RBtree Wrong ])
type Wrong = <red elem='a>( [ Rtree Btree ]
| [ Btree Rtree ])
let balance ( Unbal ->Rtree ; ('b \ Unbal) ->('b \ Unbal) )
| <blk (z)>[ <red (y)>[ <red (x)>[ a b ] c ] d ]
| <blk (z)>[ <red (x)>[ a <red (y)>[ b c ] ] d ]
| <blk (x)>[ a <red (z)>[ <red (y)>[ b c ] d ] ]
| <blk (x)>[ a <red (y)>[ b <red (z)>[ c d ] ] ]
-> <red (y)>[ <blk (x)>[ a b ] <blk (z)>[ c d ] ]
| x -> x
;;
This diff is collapsed.
module V = struct
type t = { id : string; repr : string }
let dump ppf t =
let dump ppf t =
let r = if t.repr = t.id then "" else Format.sprintf ";repr=%s" t.repr in
Format.fprintf ppf "{id=%s;%s}" t.id r
let compare x y = Pervasives.compare x.id y.id
......@@ -48,6 +48,7 @@ module Set = struct
let inter = cap
let cardinal = length
let mem t v = mem v t
let fold = fold
end
type 'a pairvar = [ `Atm of 'a | var ]
......
......@@ -18,7 +18,7 @@ module Set : sig
val pp : Format.formatter -> t -> unit
val printf : t -> unit
val is_empty : t -> bool
val empty : t
val empty : t
val singleton : var -> t
val union : t -> t -> t
val diff : t -> t -> t
......@@ -28,6 +28,7 @@ module Set : sig
val subset : t -> t -> bool
val cardinal : t -> int
val from_list : var list -> t
val fold : ('a -> var -> 'a) -> 'a -> t -> 'a
end
type 'a pairvar = [ `Atm of 'a | var ]
......
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