Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LARA
inox
Commits
95428726
Commit
95428726
authored
11 years ago
by
Etienne Kneuss
Browse files
Options
Downloads
Patches
Plain Diff
Fix case-study
parent
da00c47d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
testcases/case-studies/Lambda.scala
+42
-22
42 additions, 22 deletions
testcases/case-studies/Lambda.scala
with
42 additions
and
22 deletions
testcases/case-studies/Lambda.scala
+
42
−
22
View file @
95428726
...
@@ -9,26 +9,21 @@ object Lang {
...
@@ -9,26 +9,21 @@ object Lang {
def
isLiteral
(
l
:
Expr
)
=
l
match
{
def
isLiteral
(
l
:
Expr
)
=
l
match
{
case
_:
Var
=>
true
case
_:
Var
=>
true
case
_:
Abs
=>
true
case
_:
Abs
=>
true
case
_:
BoolLit
=>
true
case
_:
IntLit
=>
true
//case _: Record => true
//case _: Record => true
case
_
=>
false
case
_
=>
false
}
}
abstract
class
Expr
abstract
class
Expr
case
class
Var
(
id
:
Id
)
extends
Expr
case
class
Var
(
id
:
Id
)
extends
Expr
case
class
IntLit
(
v
:
Int
)
extends
Expr
case
class
BoolLit
(
v
:
Boolean
)
extends
Expr
case
class
App
(
f
:
Expr
,
arg
:
Expr
)
extends
Expr
case
class
App
(
f
:
Expr
,
arg
:
Expr
)
extends
Expr
case
class
Abs
(
b
:
Id
,
tpe
:
Type
,
e
:
Expr
)
extends
Expr
case
class
Abs
(
b
:
Id
,
tpe
:
Type
,
e
:
Expr
)
extends
Expr
//case class Record(fields: Map[Id, Expr]) extends Expr
//case class Record(fields: Map[Id, Expr]) extends Expr
//case class Select(r: Expr, f: Var) extends Expr
//case class Select(r: Expr, f: Var) extends Expr
abstract
class
Type
abstract
class
Type
case
object
TBool
extends
Type
case
class
Param
(
k
:
Int
)
extends
Type
case
object
TInt
extends
Type
case
class
TFunction
(
from
:
Type
,
to
:
Type
)
extends
Type
case
class
TApp
(
from
:
Type
,
to
:
Type
)
extends
Type
//case class TRecord(fields: Map[Id, Type]) extends Type
//case class TRecord(fields: Map[Id, Type]) extends Type
}
}
...
@@ -45,15 +40,9 @@ object TypeChecker {
...
@@ -45,15 +40,9 @@ object TypeChecker {
None
()
None
()
}
}
case
_:
IntLit
=>
Some
(
TInt
)
case
_:
BoolLit
=>
Some
(
TBool
)
case
App
(
f
,
arg
)
=>
case
App
(
f
,
arg
)
=>
typeOf
(
f
,
None
(),
env
)
match
{
typeOf
(
f
,
None
(),
env
)
match
{
case
Some
(
T
App
(
from
,
to
))
=>
case
Some
(
T
Function
(
from
,
to
))
=>
typeOf
(
arg
,
Some
(
from
),
env
)
match
{
typeOf
(
arg
,
Some
(
from
),
env
)
match
{
case
Some
(
_
)
=>
Some
(
to
)
case
Some
(
_
)
=>
Some
(
to
)
case
_
=>
None
()
case
_
=>
None
()
...
@@ -63,10 +52,10 @@ object TypeChecker {
...
@@ -63,10 +52,10 @@ object TypeChecker {
case
Abs
(
id
,
tpe
,
e
)
=>
case
Abs
(
id
,
tpe
,
e
)
=>
val
nenv
=
env
.
updated
(
id
,
tpe
)
val
nenv
=
env
.
updated
(
id
,
tpe
)
(
exp
,
typeOf
(
e
,
None
(),
nenv
))
match
{
(
exp
,
typeOf
(
e
,
None
(),
nenv
))
match
{
case
(
Some
(
T
App
(
from
,
to
)),
Some
(
to2
))
if
(
from
==
tpe
)
&&
(
to
==
to2
)
=>
case
(
Some
(
T
Function
(
from
,
to
)),
Some
(
to2
))
if
(
from
==
tpe
)
&&
(
to
==
to2
)
=>
Some
(
T
App
(
tpe
,
to2
))
Some
(
T
Function
(
tpe
,
to2
))
case
(
None
(),
Some
(
to2
))
=>
case
(
None
(),
Some
(
to2
))
=>
Some
(
T
App
(
tpe
,
to2
))
Some
(
T
Function
(
tpe
,
to2
))
case
_
=>
case
_
=>
None
()
None
()
}
}
...
@@ -82,6 +71,10 @@ object TypeChecker {
...
@@ -82,6 +71,10 @@ object TypeChecker {
def
typeChecks
(
e
:
Expr
)
:
Boolean
=
{
def
typeChecks
(
e
:
Expr
)
:
Boolean
=
{
typeOf
(
e
,
None
(),
Map
[
Id
,
Type
]()).
isDefined
typeOf
(
e
,
None
(),
Map
[
Id
,
Type
]()).
isDefined
}
}
def
typeOf
(
e
:
Expr
)
:
Option
[
Type
]
=
{
typeOf
(
e
,
None
(),
Map
[
Id
,
Type
]())
}
}
}
object
Evaluator
{
object
Evaluator
{
...
@@ -111,11 +104,38 @@ object Evaluator {
...
@@ -111,11 +104,38 @@ object Evaluator {
object
Main
{
object
Main
{
import
Lang._
import
Lang._
import
Evaluator._
import
Evaluator._
import
TypeChecker._
def
synthesize_identity
()
:
Expr
=
{
choose
{
(
e
:
Expr
)
=>
val
t_identity
:
Type
=
TFunction
(
Param
(
1
),
Param
(
1
))
typeOf
(
e
)
==
Some
(
t_identity
)
}
}
def
synthesize_K
()
:
Expr
=
{
choose
{
(
e
:
Expr
)
=>
val
t1
:
Type
=
TFunction
(
Param
(
1
),
TFunction
(
Param
(
2
),
Param
(
1
)))
typeOf
(
e
)
==
Some
(
t1
)
}
}
def
synthesize_K2
()
:
Expr
=
{
choose
{
(
e
:
Expr
)
=>
val
t1
:
Type
=
TFunction
(
Param
(
1
),
TFunction
(
Param
(
2
),
Param
(
2
)))
typeOf
(
e
)
==
Some
(
t1
)
}
}
def
test
()
:
Expr
=
{
val
x
=
Var
(
Id
(
0
))
val
y
=
Var
(
Id
(
1
))
eval
(
App
(
Abs
(
Id
(
0
),
TInt
,
x
),
IntLit
(
42
)))
def
synthesize_S
()
:
Expr
=
{
choose
{
(
e
:
Expr
)
=>
val
tz
=
Param
(
1
)
val
ty
=
TFunction
(
Param
(
1
),
Param
(
2
))
val
tx
=
TFunction
(
Param
(
1
),
TFunction
(
Param
(
2
),
Param
(
3
)))
val
t1
:
Type
=
TFunction
(
tx
,
TFunction
(
ty
,
TFunction
(
tz
,
Param
(
3
))))
typeOf
(
e
)
==
Some
(
t1
)
}
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment