Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
uva
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
uva
Commits
d793bb9e
Commit
d793bb9e
authored
Dec 04, 2011
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
funclang series5: Added freevars function for ass12.
parent
e052f91d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
9 deletions
+25
-9
funclang-taddeus/series5/ass12.ml
funclang-taddeus/series5/ass12.ml
+25
-9
No files found.
funclang-taddeus/series5/ass12.ml
View file @
d793bb9e
...
...
@@ -43,19 +43,35 @@ let rec expr2string =
|
Cond
(
cond
,
e1
,
e2
)
->
"if "
^
expr2string
(
cond
)
^
" then "
^
expr2string
(
e1
)
^
" else "
^
expr2string
(
e2
)
|
Fun
(
arg
,
e
)
->
"fun "
^
arg
^
" -> "
^
expr2string
(
e
)
|
Fun
(
arg
,
e
)
->
"fun
c
"
^
arg
^
" -> "
^
expr2string
(
e
)
|
FunAp
(
e1
,
e2
)
->
"("
^
expr2string
(
e1
)
^
" "
^
expr2string
(
e2
)
^
")"
|
Let
(
var
,
e1
,
e2
)
->
"let "
^
var
^
" = "
^
expr2string
(
e1
)
^
" in "
^
expr2string
(
e2
)
|
LetRec
(
var
,
e1
,
e2
)
->
"let rec "
^
var
^
" = "
^
expr2string
(
e1
)
^
" in "
^
expr2string
(
e2
)
;;
(* let a = 1 in b *)
print_endline
(
expr2string
(
Let
(
"a"
,
(
Num
1
)
,
(
Var
"b"
))));;
(* a + 3 *)
print_endline
(
expr2string
(
BinopAp
(
Add
,
Var
"a"
,
Num
3
)));;
let
freevars
e
=
let
rec
free_vars
bound_vars
=
function
Num
_
|
Bool
_
->
[]
|
Var
v
when
List
.
mem
v
bound_vars
->
[]
|
Var
v
->
[
v
]
|
MonopAp
(
_
,
e
)
->
free_vars
bound_vars
e
|
BinopAp
(
_
,
e1
,
e2
)
|
FunAp
(
e1
,
e2
)
->
free_vars
bound_vars
e1
@
free_vars
bound_vars
e2
|
Cond
(
cond
,
e1
,
e2
)
->
free_vars
bound_vars
cond
@
free_vars
bound_vars
e1
@
free_vars
bound_vars
e2
|
Fun
(
arg
,
e
)
->
free_vars
(
arg
::
bound_vars
)
e
|
Let
(
v
,
e1
,
e2
)
->
free_vars
(
v
::
bound_vars
)
e2
@
free_vars
bound_vars
e1
|
LetRec
(
v
,
e1
,
e2
)
->
let
bound
=
v
::
bound_vars
in
free_vars
bound
e2
@
free_vars
bound
e1
in
free_vars
[]
e
(* -a *)
print_endline
(
expr2string
(
MonopAp
(
Neg
,
Var
"a"
)));;
(*let rec subs e var replacement =
let free = freevars e in
match e with
| Num _ | Bool _ -> e
| Var v when List.mem v bound_vars -> []
| Var v -> [v]*)
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