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
4dc8cb3b
Commit
4dc8cb3b
authored
14 years ago
by
Ali Sinan Köksal
Browse files
Options
Downloads
Patches
Plain Diff
Code generator for `compose' methods up to a given arity
parent
19ee483e
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/cp/Converter.scala
+3
-0
3 additions, 0 deletions
src/cp/Converter.scala
src/cp/Terms.scala
+5
-8
5 additions, 8 deletions
src/cp/Terms.scala
src/cp/Utils.scala
+48
-0
48 additions, 0 deletions
src/cp/Utils.scala
with
56 additions
and
8 deletions
src/cp/Converter.scala
+
3
−
0
View file @
4dc8cb3b
...
...
@@ -10,4 +10,7 @@ class Converter(expr2scala : (Expr => Any)) {
def
exprSeq2scala2
[
A
,
B
](
exprs
:
Seq
[
Expr
])
:
(
A
,
B
)
=
(
expr2scala
(
exprs
(
0
)).
asInstanceOf
[
A
],
expr2scala
(
exprs
(
1
)).
asInstanceOf
[
B
])
def
exprSeq2scala3
[
A
,
B
,
C
](
exprs
:
Seq
[
Expr
])
:
(
A
,
B
,
C
)
=
(
expr2scala
(
exprs
(
0
)).
asInstanceOf
[
A
],
expr2scala
(
exprs
(
1
)).
asInstanceOf
[
B
],
expr2scala
(
exprs
(
2
)).
asInstanceOf
[
C
])
}
This diff is collapsed.
Click to expand it.
src/cp/Terms.scala
+
5
−
8
View file @
4dc8cb3b
...
...
@@ -220,22 +220,19 @@ object Terms {
/********** TERM METHODS **********/
/** compose_i_j_k will compose f (of arity j) and g (of arity k) as "g∘f" by
* inserting arguments of f in place of argument i of g */
private
def
compose_0_1_1
[
T1
,
T2
,
T3
](
f
:
Term
[
T1
,
T2
],
g
:
Term
[
T2
,
T3
])
:
Term1
[
T
1
,
T3
]
=
{
private
def
compose_0_1_1
[
A1
,
R1
,
R2
](
f
:
Term
[
(
A1
)
,
R1
],
g
:
Term
[
(
R1
)
,
R2
])
:
Term1
[
A
1
,
R2
]
=
{
val
(
newExpr
,
newTypes
)
=
compose
(
f
,
g
,
0
,
1
,
1
)
Term1
(
f
.
program
,
newExpr
,
newTypes
,
f
.
converter
)
}
private
def
compose_0_2_1
[
T1
,
T2
,
R1
,
R2
](
f
:
Term
[(
T1
,
T2
)
,
R1
],
g
:
Term
[
R1
,
R2
])
:
Term2
[
T1
,
T2
,
R2
]
=
{
private
def
compose_0_2_1
[
A1
,
A2
,
R1
,
R2
](
f
:
Term
[(
A1
,
A2
)
,
R1
],
g
:
Term
[(
R1
)
,
R2
])
:
Term2
[
A1
,
A2
,
R2
]
=
{
val
(
newExpr
,
newTypes
)
=
compose
(
f
,
g
,
0
,
2
,
1
)
Term2
(
f
.
program
,
newExpr
,
newTypes
,
f
.
converter
)
}
private
def
compose_0_1_2
[
T1
,
R1
,
T2
,
R2
](
f
:
Term
[
T1
,
R1
],
g
:
Term
[(
R1
,
T2
)
,
R2
])
:
Term2
[
T1
,
T2
,
R2
]
=
{
private
def
compose_0_1_2
[
A1
,
R1
,
B2
,
R2
](
f
:
Term
[(
A1
)
,
R1
],
g
:
Term
[(
R1
,
B2
)
,
R2
])
:
Term2
[
A1
,
B2
,
R2
]
=
{
val
(
newExpr
,
newTypes
)
=
compose
(
f
,
g
,
0
,
1
,
2
)
Term2
(
f
.
program
,
newExpr
,
newTypes
,
f
.
converter
)
}
private
def
compose_1_1_2
[
T1
,
R1
,
T2
,
R2
](
f
:
Term
[
T1
,
R1
],
g
:
Term
[(
T2
,
R1
)
,
R2
])
:
Term2
[
T2
,
T1
,
R2
]
=
{
private
def
compose_1_1_2
[
A1
,
R1
,
B1
,
R2
](
f
:
Term
[(
A1
)
,
R1
],
g
:
Term
[(
B1
,
R1
)
,
R2
])
:
Term2
[
B1
,
A1
,
R2
]
=
{
val
(
newExpr
,
newTypes
)
=
compose
(
f
,
g
,
1
,
1
,
2
)
Term2
(
f
.
program
,
newExpr
,
newTypes
,
f
.
converter
)
}
...
...
@@ -255,7 +252,7 @@ object Terms {
val
indexToReplace
=
deBruijnG
(
index
)
val
newExpr
=
replace
(
Map
(
indexToReplace
->
renamedExprF
),
renamedExprG
)
val
newTypes
=
g
.
types
.
take
(
index
)
++
f
.
types
++
g
.
types
.
drop
(
index
+
nf
)
val
newTypes
=
g
.
types
.
take
(
index
)
++
f
.
types
++
g
.
types
.
drop
(
index
+
1
)
assert
(
newTypes
.
size
==
nf
+
ng
-
1
)
(
newExpr
,
newTypes
)
}
...
...
This diff is collapsed.
Click to expand it.
src/cp/Utils.scala
0 → 100644
+
48
−
0
View file @
4dc8cb3b
package
cp
object
Utils
{
/** Generate `compose' methods for terms */
object
GenerateCompose
{
private
def
indent
(
s
:
String
)
:
String
=
s
.
split
(
"\n"
).
mkString
(
" "
,
"\n "
,
""
)
def
apply
(
maxArity
:
Int
)
:
String
=
{
val
methods
:
Seq
[
String
]
=
(
for
(
arityG
<-
1
to
maxArity
)
yield
{
for
(
arityF
<-
1
to
(
maxArity
-
arityG
+
1
))
yield
{
for
(
index
<-
0
until
arityG
)
yield
{
val
sb
=
new
scala
.
collection
.
mutable
.
StringBuilder
sb
.
append
(
"private def compose_"
)
sb
.
append
(
index
+
"_"
+
arityF
+
"_"
+
arityG
)
val
fParams
=
(
1
to
arityF
).
map
(
"A"
+
_
)
val
gParams
=
(
1
to
arityG
).
map
(
"B"
+
_
)
val
replacedGParams
=
gParams
.
take
(
index
)
++
Seq
(
"R1"
)
++
gParams
.
drop
(
index
+
1
)
val
allParams
=
fParams
++
Seq
(
"R1"
)
++
(
gParams
.
take
(
index
)
++
gParams
.
drop
(
index
+
1
))
++
Seq
(
"R2"
)
sb
.
append
(
allParams
.
mkString
(
"["
,
","
,
"]"
))
sb
.
append
(
"(f : Term["
)
sb
.
append
(
fParams
.
mkString
(
"("
,
","
,
")"
))
sb
.
append
(
",R1], g : Term["
)
sb
.
append
(
replacedGParams
.
mkString
(
"("
,
","
,
")"
))
sb
.
append
(
",R2]) : Term"
)
val
newTermSize
=
arityG
+
arityF
-
1
val
resultParams
=
gParams
.
take
(
index
)
++
fParams
++
gParams
.
drop
(
index
+
1
)
++
Seq
(
"R2"
)
sb
.
append
(
resultParams
.
mkString
(
newTermSize
+
"["
,
","
,
"]"
))
sb
.
append
(
" = {\n"
)
sb
.
append
(
indent
(
"val (newExpr, newTypes) = compose(f, g, "
+
index
+
", "
+
arityF
+
", "
+
arityG
+
")"
))
sb
.
append
(
"\n"
)
sb
.
append
(
indent
(
"Term"
+
newTermSize
+
"(f.program, newExpr, newTypes, f.converter)"
))
sb
.
append
(
"\n"
)
sb
.
append
(
"}"
)
sb
.
toString
}
}
}).
flatten
.
flatten
methods
.
mkString
(
"\n"
)
}
}
}
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