|
|
||
|
|
Start of topic | Skip to actions
Polymorphic RecursionTo summarize the work we've been doing with interpreters, look at the types of the two eval functions we've implemented.
eval: term -> env -> value
t_eval: forall env, typ. ('(env), '(typ)) t_term -> '(eval_env env) -> '(eval_typ typ)
Can these variables be OCaml variables instead of Coq variables?: (env, typ) t_term -> '(eval_env env) -> typ In the first solution, using Coq variables, typ would be a representation of an OCaml type: typ ::= TInt | TFun of typ * typ;; In the second, typ would be any OCaml type: typ ::= int | int -> int | int -> int -> int | ...;; Dr. Taha is wondering if this would work, or be implementable. Let's explore what happens in this type definition:
type (env, typ) t_term =
| TInt of let env' in int : (env', int) t_term
| TVarZ of let env', t' in unit : ( (env', t') pair, t') t_term
...
| TApp of let t1, t2, env' in
(env', t1) t_term * (env', t1 -> t2) t_term : (env', t2) t_term
...
Would those last few lines work, both the TVarZ? and the TApp? Lets look at the eval function:
t_eval = ....
| TApp .|t1, t2, env'| (e1, e2) =
(t_eval .|env'| e1 env) (t_eval .|env'| e2 env)
There seems to be no guarantee here that the first expression in the application is an arrow type. A regular data type is:
a list =
| A ....
a list ....
| B ....
a list ....
A non-regular data type is:
a list =
| C ....
(a * a) list ....
| D ....
(a list) list
The problem here is that recursion that follows the structure of the type is impossible (or at least limited and difficult). What about:
a list =
| ....
int list ....
This is still regular, but you'll only be able to use int lists. The polymorphic alpha will go unused. Hindley Milner type inference systems are only decidable if you don't have polymorphic recursion. An example of Polymorphic Recursion: f : a list -> X x : a list let rec f x = ... f y f z okay if the data type of f is the same for every use in the recursive call. That is, every time you call f from within f, you must assume it has the same type as before. If y has type (a * a) list, the recursion doesn't make sense, and it will fail. This is due to the fact that in OCaml, we are quantifying over all type of f from the top level, outside of the use of f. If we could have a nested forall, like we get in concoqtion, this would not be a problem. Jun suggested a third solution: what about a type that is quantified over all OCaml types, instead of represenatations of OCaml types: forall (typ:OCaml_type). ...
Topic Actions: Edit | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r3 < r2 < r1 | More topic actions
Webs: Main | TWiki | Africa | EmbeddedSystems | Gpce | Houston | International | K12 | MetaOCaml | MulticoreOCR | ProgrammingLanguages | RAP | RIDL | Sandbox | SpeechClub | Teaching | Texbot | WG211 Web Actions: |
|
This work is licensed under a Creative Commons Attribution 2.5 License. Please follow our citation guidelines.