annotate lib/ur/top.urs @ 983:2cd8c1aa0d3a

Add tail call optimization to interpretation
author Adam Chlipala <adamc@hcoop.net>
date Thu, 24 Sep 2009 15:45:37 -0400
parents 37dd42935dad
children 10114d7b7477
rev   line source
adamc@623 1 (** Row folding *)
adamc@623 2
adamc@631 3 con folder :: K --> {K} -> Type
adamc@623 4
adamc@653 5 val fold : K --> tf :: ({K} -> Type)
adamc@653 6 -> (nm :: Name -> v :: K -> r :: {K} -> [[nm] ~ r] =>
adamc@653 7 tf r -> tf ([nm = v] ++ r))
adamc@653 8 -> tf []
adamc@653 9 -> r :: {K} -> folder r -> tf r
adamc@653 10
adamc@627 11 structure Folder : sig
adamc@627 12 val nil : K --> folder (([]) :: {K})
adamc@627 13 val cons : K --> r ::: {K} -> nm :: Name -> v :: K
adamc@629 14 -> [[nm] ~ r] => folder r -> folder ([nm = v] ++ r)
adamc@628 15 val concat : K --> r1 ::: {K} -> r2 ::: {K}
adamc@629 16 -> [r1 ~ r2] => folder r1 -> folder r2 -> folder (r1 ++ r2)
adamc@630 17 val mp : K1 --> K2 --> f ::: (K1 -> K2) -> r ::: {K1}
adamc@630 18 -> folder r -> folder (map f r)
adamc@627 19 end
adamc@627 20
adamc@623 21
adamc@422 22 val not : bool -> bool
adamc@422 23
adamc@898 24 con id = K ==> fn t :: K => t
adamc@329 25 con record = fn t :: {Type} => $t
adamc@637 26 con fst = K1 ==> K2 ==> fn t :: (K1 * K2) => t.1
adamc@637 27 con snd = K1 ==> K2 ==> fn t :: (K1 * K2) => t.2
adamc@637 28 con fst3 = K1 ==> K2 ==> K3 ==> fn t :: (K1 * K2 * K3) => t.1
adamc@637 29 con snd3 = K1 ==> K2 ==> K3 ==> fn t :: (K1 * K2 * K3) => t.2
adamc@637 30 con thd3 = K1 ==> K2 ==> K3 ==> fn t :: (K1 * K2 * K3) => t.3
adamc@329 31
adamc@643 32 con mapU = K ==> fn f :: K => map (fn _ :: Unit => f)
adamc@445 33
adamc@339 34 con ex = fn tf :: (Type -> Type) =>
adamc@355 35 res ::: Type -> (choice :: Type -> tf choice -> res) -> res
adamc@339 36
adamc@339 37 val ex : tf :: (Type -> Type) -> choice :: Type -> tf choice -> ex tf
adamc@339 38
adamc@325 39 val compose : t1 ::: Type -> t2 ::: Type -> t3 ::: Type
adamc@355 40 -> (t2 -> t3) -> (t1 -> t2) -> (t1 -> t3)
adamc@325 41
adamc@777 42 val show_option : t ::: Type -> show t -> show (option t)
adamc@777 43 val read_option : t ::: Type -> read t -> read (option t)
adamc@777 44
adamc@720 45 val txt : t ::: Type -> ctx ::: {Unit} -> use ::: {Type} -> show t -> t
adamc@720 46 -> xml ctx use []
adamc@329 47
adamc@898 48 val mp : K --> tf1 :: (K -> Type) -> tf2 :: (K -> Type)
adamc@898 49 -> (t ::: K -> tf1 t -> tf2 t)
adamc@898 50 -> r :: {K} -> folder r -> $(map tf1 r) -> $(map tf2 r)
adamc@937 51 val map2 : K --> tf1 :: (K -> Type) -> tf2 :: (K -> Type) -> tf :: (K -> Type)
adamc@937 52 -> (t ::: K -> tf1 t -> tf2 t -> tf t)
adamc@937 53 -> r :: {K} -> folder r -> $(map tf1 r) -> $(map tf2 r) -> $(map tf r)
adamc@937 54 val map3 : K --> tf1 :: (K -> Type) -> tf2 :: (K -> Type) -> tf3 :: (K -> Type) -> tf :: (K -> Type)
adamc@937 55 -> (t ::: K -> tf1 t -> tf2 t -> tf3 t -> tf t)
adamc@937 56 -> r :: {K} -> folder r -> $(map tf1 r) -> $(map tf2 r) -> $(map tf3 r) -> $(map tf r)
adamc@898 57
adamc@411 58 val foldUR : tf :: Type -> tr :: ({Unit} -> Type)
adamc@411 59 -> (nm :: Name -> rest :: {Unit}
adamc@629 60 -> [[nm] ~ rest] =>
adamc@411 61 tf -> tr rest -> tr ([nm] ++ rest))
adamc@643 62 -> tr [] -> r :: {Unit} -> folder r -> $(mapU tf r) -> tr r
adamc@411 63
adamc@418 64 val foldUR2 : tf1 :: Type -> tf2 :: Type -> tr :: ({Unit} -> Type)
adamc@418 65 -> (nm :: Name -> rest :: {Unit}
adamc@629 66 -> [[nm] ~ rest] =>
adamc@418 67 tf1 -> tf2 -> tr rest -> tr ([nm] ++ rest))
adamc@643 68 -> tr [] -> r :: {Unit} -> folder r -> $(mapU tf1 r) -> $(mapU tf2 r) -> tr r
adamc@418 69
adamc@720 70 val foldURX2: tf1 :: Type -> tf2 :: Type -> ctx :: {Unit}
adamc@418 71 -> (nm :: Name -> rest :: {Unit}
adamc@629 72 -> [[nm] ~ rest] =>
adamc@720 73 tf1 -> tf2 -> xml ctx [] [])
adamc@720 74 -> r :: {Unit} -> folder r -> $(mapU tf1 r) -> $(mapU tf2 r) -> xml ctx [] []
adamc@418 75
adamc@623 76 val foldR : K --> tf :: (K -> Type) -> tr :: ({K} -> Type)
adamc@623 77 -> (nm :: Name -> t :: K -> rest :: {K}
adamc@629 78 -> [[nm] ~ rest] =>
adamc@355 79 tf t -> tr rest -> tr ([nm = t] ++ rest))
adamc@632 80 -> tr [] -> r :: {K} -> folder r -> $(map tf r) -> tr r
adamc@336 81
adamc@623 82 val foldR2 : K --> tf1 :: (K -> Type) -> tf2 :: (K -> Type)
adamc@623 83 -> tr :: ({K} -> Type)
adamc@623 84 -> (nm :: Name -> t :: K -> rest :: {K}
adamc@629 85 -> [[nm] ~ rest] =>
adamc@623 86 tf1 t -> tf2 t -> tr rest -> tr ([nm = t] ++ rest))
adamc@623 87 -> tr []
adamc@632 88 -> r :: {K} -> folder r -> $(map tf1 r) -> $(map tf2 r) -> tr r
adamc@623 89
adamc@910 90 val foldR3 : K --> tf1 :: (K -> Type) -> tf2 :: (K -> Type) -> tf3 :: (K -> Type)
adamc@910 91 -> tr :: ({K} -> Type)
adamc@910 92 -> (nm :: Name -> t :: K -> rest :: {K}
adamc@910 93 -> [[nm] ~ rest] =>
adamc@910 94 tf1 t -> tf2 t -> tf3 t -> tr rest -> tr ([nm = t] ++ rest))
adamc@910 95 -> tr []
adamc@910 96 -> r :: {K} -> folder r -> $(map tf1 r) -> $(map tf2 r) -> $(map tf3 r) -> tr r
adamc@910 97
adamc@720 98 val foldRX : K --> tf :: (K -> Type) -> ctx :: {Unit}
adamc@623 99 -> (nm :: Name -> t :: K -> rest :: {K}
adamc@629 100 -> [[nm] ~ rest] =>
adamc@720 101 tf t -> xml ctx [] [])
adamc@720 102 -> r :: {K} -> folder r -> $(map tf r) -> xml ctx [] []
adamc@623 103
adamc@720 104 val foldRX2 : K --> tf1 :: (K -> Type) -> tf2 :: (K -> Type) -> ctx :: {Unit}
adamc@623 105 -> (nm :: Name -> t :: K -> rest :: {K}
adamc@629 106 -> [[nm] ~ rest] =>
adamc@720 107 tf1 t -> tf2 t -> xml ctx [] [])
adamc@632 108 -> r :: {K} -> folder r
adamc@720 109 -> $(map tf1 r) -> $(map tf2 r) -> xml ctx [] []
adamc@445 110
adamc@910 111 val foldRX3 : K --> tf1 :: (K -> Type) -> tf2 :: (K -> Type) -> tf3 :: (K -> Type) -> ctx :: {Unit}
adamc@910 112 -> (nm :: Name -> t :: K -> rest :: {K}
adamc@910 113 -> [[nm] ~ rest] =>
adamc@910 114 tf1 t -> tf2 t -> tf3 t -> xml ctx [] [])
adamc@910 115 -> r :: {K} -> folder r
adamc@910 116 -> $(map tf1 r) -> $(map tf2 r) -> $(map tf3 r) -> xml ctx [] []
adamc@910 117
adamc@682 118 val queryI : tables ::: {{Type}} -> exps ::: {Type}
adamc@682 119 -> [tables ~ exps] =>
adamc@682 120 sql_query tables exps
adamc@682 121 -> ($(exps ++ map (fn fields :: {Type} => $fields) tables)
adamc@682 122 -> transaction unit)
adamc@682 123 -> transaction unit
adamc@682 124
adamc@720 125 val queryX : tables ::: {{Type}} -> exps ::: {Type} -> ctx ::: {Unit}
adamc@629 126 -> [tables ~ exps] =>
adamc@632 127 sql_query tables exps
adamc@632 128 -> ($(exps ++ map (fn fields :: {Type} => $fields) tables)
adamc@720 129 -> xml ctx [] [])
adamc@720 130 -> transaction (xml ctx [] [])
adamc@341 131
adamc@720 132 val queryX' : tables ::: {{Type}} -> exps ::: {Type} -> ctx ::: {Unit}
adamc@629 133 -> [tables ~ exps] =>
adamc@632 134 sql_query tables exps
adamc@632 135 -> ($(exps ++ map (fn fields :: {Type} => $fields) tables)
adamc@720 136 -> transaction (xml ctx [] []))
adamc@720 137 -> transaction (xml ctx [] [])
adamc@469 138
adamc@355 139 val oneOrNoRows : tables ::: {{Type}} -> exps ::: {Type}
adamc@629 140 -> [tables ~ exps] =>
adamc@629 141 sql_query tables exps
adamc@629 142 -> transaction
adamc@629 143 (option
adamc@629 144 $(exps
adamc@629 145 ++ map (fn fields :: {Type} => $fields) tables))
adamc@440 146
adamc@440 147 val oneRow : tables ::: {{Type}} -> exps ::: {Type}
adamc@629 148 -> [tables ~ exps] =>
adamc@629 149 sql_query tables exps
adamc@629 150 -> transaction
adamc@629 151 $(exps
adamc@629 152 ++ map (fn fields :: {Type} => $fields) tables)
adamc@629 153
adamc@470 154 val eqNullable : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type}
adamc@470 155 -> t ::: Type -> sql_injectable (option t)
adamc@470 156 -> sql_exp tables agg exps (option t)
adamc@470 157 -> sql_exp tables agg exps (option t)
adamc@470 158 -> sql_exp tables agg exps bool
adamc@470 159
adamc@470 160 val eqNullable' : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type}
adamc@470 161 -> t ::: Type -> sql_injectable (option t)
adamc@470 162 -> sql_exp tables agg exps (option t)
adamc@470 163 -> option t
adamc@470 164 -> sql_exp tables agg exps bool