13 changed files with 150 additions and 96 deletions
@ -1,42 +1,9 @@ |
|||
type primitive_type = Unit | Bool |
|||
|
|||
type type_variable = string |
|||
|
|||
type dddddml_type = |
|||
| Variable of type_variable |
|||
| Primitive of primitive_type |
|||
| Arrow of dddddml_type * dddddml_type |
|||
|
|||
(* true if t appears in t' *) |
|||
let rec contains t t' = |
|||
if t = t' then true |
|||
else |
|||
match t' with |
|||
| Arrow (t1, t2) -> |
|||
contains t t1 || contains t t2 |
|||
| _ -> |
|||
false |
|||
|
|||
(** substitute t by t' in e *) |
|||
let subst (t, t') e = |
|||
let rec aux e = |
|||
if e = t then t' |
|||
else |
|||
match e with |
|||
| Variable _ | Primitive _ -> |
|||
e |
|||
| Arrow (t1, t2) -> |
|||
Arrow (aux t1, aux t2) |
|||
in |
|||
aux e |
|||
|
|||
let primitive_card = function Unit -> 1 | Bool -> 2 |
|||
|
|||
let rec card = function |
|||
| Variable x -> |
|||
failwith (Format.sprintf "unknown card for type variable `%s`" x) |
|||
| Primitive t -> |
|||
primitive_card t |
|||
| Arrow (t1, t2) -> |
|||
int_of_float |
|||
@@ Float.pow (float_of_int @@ card t2) (float_of_int @@ card t1) |
|||
include Typlib.Types.Make (struct |
|||
type nonrec primitive_type = primitive_type |
|||
|
|||
let primitive_card = primitive_card |
|||
end) |
|||
|
@ -0,0 +1,3 @@ |
|||
(library |
|||
(public_name typlib) |
|||
(modules types)) |
@ -0,0 +1,60 @@ |
|||
module Make (M : sig |
|||
type primitive_type |
|||
|
|||
val primitive_card : primitive_type -> int |
|||
end) = |
|||
struct |
|||
type type_variable = string |
|||
|
|||
type type_expression = |
|||
| Variable of type_variable |
|||
| Primitive of M.primitive_type |
|||
| Arrow of type_expression * type_expression |
|||
|
|||
(** true if t appears in t' *) |
|||
let contains t t' = |
|||
let rec aux = function |
|||
| x when x = t -> |
|||
true |
|||
| Arrow (t1, t2) -> |
|||
aux t1 || aux t2 |
|||
| _ -> |
|||
false |
|||
in |
|||
aux t' |
|||
|
|||
(** substitue t by t' in e *) |
|||
let subst (t, t') e = |
|||
let rec aux = function |
|||
| x when x = t -> |
|||
t' |
|||
| (Variable _ | Primitive _) as x -> |
|||
x |
|||
| Arrow (t1, t2) -> |
|||
Arrow (aux t1, aux t2) |
|||
in |
|||
aux e |
|||
|
|||
let rec comp = function |
|||
| Primitive _, Variable _ | Variable _, Primitive _ -> |
|||
true |
|||
| Arrow (t1, t2), Arrow (t3, t4) -> |
|||
comp (t1, t3) && comp (t2, t4) |
|||
| Primitive x, Primitive y -> |
|||
x = y |
|||
| Variable x, Variable y -> |
|||
x = y |
|||
| Primitive _, Arrow _ | Arrow _, Primitive _ -> |
|||
false |
|||
| Arrow _, Variable _ | Variable _, Arrow _ -> |
|||
false |
|||
|
|||
let rec card = function |
|||
| Variable x -> |
|||
failwith (Format.sprintf "unknown card for type variable `%s`" x) |
|||
| Primitive t -> |
|||
M.primitive_card t |
|||
| Arrow (t1, t2) -> |
|||
int_of_float |
|||
@@ Float.pow (float_of_int @@ card t2) (float_of_int @@ card t1) |
|||
end |
@ -0,0 +1,30 @@ |
|||
# This file is generated by dune, edit dune-project instead |
|||
opam-version: "2.0" |
|||
synopsis: "typlib" |
|||
description: "typlib" |
|||
maintainer: ["Léo Andrès <contact@ndrs.fr>"] |
|||
authors: ["Léo Andrès <contact@ndrs.fr>"] |
|||
license: "ISC" |
|||
homepage: "https://git.zapashcanon.fr/zapashcanon/dddddml" |
|||
doc: "https://doc.zapashcanon.fr/dddddml/" |
|||
bug-reports: "https://git.zapashcanon.fr/zapashcanon/dddddml/issues" |
|||
depends: [ |
|||
"ocaml" {>= "4.05"} |
|||
"dune" {>= "2.0"} |
|||
"bisect_ppx" {>= "1.4"} |
|||
] |
|||
build: [ |
|||
["dune" "subst"] {pinned} |
|||
[ |
|||
"dune" |
|||
"build" |
|||
"-p" |
|||
name |
|||
"-j" |
|||
jobs |
|||
"@install" |
|||
"@runtest" {with-test} |
|||
"@doc" {with-doc} |
|||
] |
|||
] |
|||
dev-repo: "git://git.zapashcanon.fr/zapashcanon/dddddml.git" |
Loading…
Reference in new issue