-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Greg Exercise 02 - bound names, other grammars #2
Comments
@Jake-Gillberg Meredith, Radestock, 2005, "A Reflective Higher-order Calculus":
So FN MUST use name equality ≡N in set operations ('∪' and '\'), not implicitly standard case classes equality (in Scala Set operations ('+', '-', '|', '&~')). Let P = for(@0 <- @(@0!(0))).((for(@0 <- @(0|0)).0) FN(P) = {@(@0!(0))} ∪ (FN(for(@0 <- @(0|0)).0) \ {@0}) = {@(@0!(0))} ∪ (FN(@(0|0))) \ {@0}) = {@(@0!(0))} ∪ ( {@(0|0)} \ {@0} ) = P.S. Because @(0|0) ≡N @0 |
@golovach-ivan Ah, yup! You are totally correct, thanks! I have a definition of name equality and structural equality working in scala here, but I don't preserve the structure of bound names, so it would be difficult to implement the Free and Bound name definitions without some modifications. |
@Jake-Gillberg
// not
override def equals(other: Any): Boolean = {
other match {
case that: Quote => p == that.p
case _ => false
}
}
// but
override def equals(other: Any): Boolean = other match {
case that: Quote => p == that.p
case _ => false
}
// not
override val hashCode: Int = {
41 + p.hashCode
}
// but
override val hashCode: Int = 41 + p.hashCode
val p = for (
(name, age, (_, houseNum)) <- Seq(("Mike", 42, ("StreetA", "house#1")), ("Anna", 25, ("StreetA", "house#1")))
) yield name
private final type FreqMap[X] = Map[X, Int]
private final object FreqMap {
def empty[X] = Map.empty[X, Int]
}
// not
final class Drop( x: Name ) extends Process( inputs = FreqMap.empty[(Name, Process)],
lifts = FreqMap.empty[(Name, Process)],
drops = Map(x -> 1),
height = 0 ) {
}
// but
final class Drop( x: Name ) extends Process( inputs = FreqMap.empty[(Name, Process)],
lifts = FreqMap.empty[(Name, Process)],
drops = Map(x -> 1),
height = 0 )
// not
final object Zero extends Process(
inputs = FreqMap.empty[(Name, Process)],
lifts = FreqMap.empty[(Name, Process)],
drops = FreqMap.empty[Name],
height = 0)
// but
final object Zero extends Process(
inputs = FreqMap.empty,
lifts = FreqMap.empty,
drops = FreqMap.empty,
height = 0)
sealed class Process(val inputs: Inputs = FreqMap.empty,
val lifts: Lifts = FreqMap.empty,
val drops: Drops = FreqMap.empty,
val height: Int = 0)
final object Zero extends Process
final class Drop(x: Name) extends Process(drops = Map(x -> 1))
final class Parallel(p: Process, q: Process) extends Process(
inputs = mergeMaps(Seq(p.inputs, q.inputs)),
lifts = mergeMaps(Seq(p.lifts, q.lifts)),
drops = mergeMaps(Seq(p.drops, q.drops)),
height = math.max(p.height, q.height))
final class Lift(x: Name, p: Process) extends Process(
lifts = Map((x, p) -> 1),
height = p.height)
final class Input(y: Name, x: Name, p: Process) extends Process(
inputs = Map((x, substitute(y, BoundName(p.height), p)) -> 1),
height = p.height + 1)
// not
override val hashCode: Int = {
41 + p.hashCode
}
// but
override val hashCode: Int = p.hashCode
// not
final class Drop( x: Name ) extends Process( inputs = FreqMap.empty[(Name, Process)],
lifts = FreqMap.empty[(Name, Process)],
drops = Map(x -> 1), // <<<=== HERE
height = 0 ) {
}
// but
final class Drop( x: Name ) extends Process( inputs = FreqMap.empty[(Name, Process)],
lifts = FreqMap.empty[(Name, Process)],
drops = FreqMap(x -> 1),
height = 0 ) {
}
private final object FreqMap {
...
def apply[X, B](elems: (X, Int)*): FreqMap[X] = Map[X, Int](elems: _*)
}
// this
object FreqMap {
def apply[X] = Map.empty[X, Int]
}
val x: FreqMap[String] = FreqMap()
val y: Seq[Int] = Seq()
// not this
object FreqMap {
def empty[X] = Map.empty[X, Int]
}
val x: FreqMap[String] = FreqMap.empty()
val y: Seq[Int] = Seq.empty() |
@Jake-Gillberg I finally caught up with Greg's lectures & am trying to catch up with the HW now. Here is my take on the 1st HW, FreeName computations. |
@Jake-Gillberg Here my take on the Arabic-numerals assignment: |
A few category theory resources:
|
Give the domain equation and the scala (or haskell) representations for the grammars of:
Add the definitions free and bound names to the scala (or haskell) representation of rho calculus
The text was updated successfully, but these errors were encountered: