Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Mark Cohen
/
thesis
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Merge Requests
0
Pipelines
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
431a0941
authored
Jun 01, 2019
by
Mark Cohen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tyscheme if necessary
parent
412d34d1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
0 deletions
LUCA-2/tyscheme.sml
LUCA-2/tyscheme.sml
0 → 100644
View file @
431a0941
structure
TyScheme
:
sig
type
tyScheme
=
{
sigmas
:
string
list
,
rhos
:
(
string
*
Ty
.
ty
)
list
,
tau
:
Ty
.
ty
}
val
generalize
:
Ty
.
ty
->
tyScheme
val
instantiate
:
tyScheme
->
Ty
.
ty
val
untyScheme
:
tyScheme
->
string
end
=
struct
type
tyScheme
=
{
sigmas
:
string
list
,
rhos
:
(
string
*
Ty
.
ty
)
list
,
tau
:
Ty
.
ty
}
local
open
Ty
in
fun
freeVars
(
Unit
|
Bool
|
Int
)
=
[]
|
freeVars
(
List
ty
)
=
freeVars
ty
|
freeVars
(
Pair
(
ty1
,
ty2
))
=
(
freeVars
ty1
)
@
(
freeVars
ty2
)
|
freeVars
(
Option
ty
)
=
freeVars
ty
|
freeVars
(
Fun
(
ty1
,
ty2
))
=
(
freeVars
ty1
)
@
(
freeVars
ty2
)
|
freeVars
(
TyVar
a
)
=
[
a
]
end
fun
generalize
ty
=
{
sigmas
=
freeVars
ty
,
rhos
=
[],
tau
=
ty
}
fun
instantiate
{
sigmas
=
sigmas
,
rhos
=
_,
tau
=
ty
}
=
foldl
(
fn
(
a
,
inner
)
=>
Unify
.
subst
(
Ty
.
freshTyVar
())
a
inner
)
ty
sigmas
local
open
Utils
in
fun
untyScheme
{
sigmas
=
sigmas
,
rhos
=
rhos
,
tau
=
ty
}
=
cat
(
(
map
(
fn
a
=>
cat
[
"
\\
/"
,
a
,
"."
])
sigmas
)
@
(
map
(
fn
(
x
,
t
)
=>
(
paren
o
spc
)
[
x
,
"::"
,
Ty
.
unty
t
])
rhos
)
@
[
Ty
.
unty
ty
]
)
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment