Created
August 18, 2018 08:59
-
-
Save mwolicki/9562b063d1d564e7c75d11b1e69447fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Tree = struct | |
type z = Z : z | |
type 'a s = S : 'a s | |
type (_,_,_) max = | |
| MaxEq : 'a -> ('a,'a,'a) max | |
| MaxSuc : ('a, 'b, 'a) max -> ('a s, 'b, 'a s) max | |
| MaxFlip : ('a, 'b, 'c) max -> ('b, 'a, 'c) max | |
let z = (MaxEq Z) |> MaxSuc |> MaxSuc |> MaxSuc |> MaxSuc |> MaxFlip | |
type ('a, _) tree = | |
| Nil : ('a, z) tree | |
| Node : 'a * ('a, 'num) tree * ('a, 'num) tree -> ('a, 'num s) tree | |
let test1_ = Nil | |
let test2 = Node ("xyz", Nil, Nil) | |
let test3 = Node ("a", test2, Node ("b", Nil, Nil)) | |
let top : type a b. (b, a s) tree -> b = function | |
| Node (k, _, _) -> k | |
let rec len : type a. (_, a) tree -> int = function | |
| Node (_, lhs, _) -> 1 + len lhs | |
| Nil -> 0 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment