Question

So I'm trying to write a function that takes a set of ternary relations and one of the middle elements which returns the set of relations where the element matches, but doesn't contain itself. (We already know what it is)

So something like this:

// addr gives us: {Book -> Name -> Addr}
fun [n:Name] : Set Book -> Addr {
    //return {b->a} where {b->n->a}
}

With joins and domain restrictions, I've only been able to manage to get the binary relations: {Book -> Name} and {Name -> Addr}. I'm not sure how I would splice these together as the Name is constant, so you can't tell the difference.

Is it possible to do this with a function, or do I need something else?

I'm an absolute beginner at this, and it seems fairly simple in a normal procedural language. However, I can't find very good documentation and it looks to me I've just got completely the wrong end of the stick on terms of how functions work in this.

Was it helpful?

Solution

Or even more simply:

fun [n:Name]: Book -> Addr {
   {b:Book,a:Addr | b->n->a in addr}
}

However, your use of the term "set of relations" and the keyword "set" in your function declaration makes me wonder if you mean something different. Note that this function returns a set of tuples, not a set of relations.

OTHER TIPS

You can probably calculate that with a definition by comprehension:

fun [n:Name]: Book -> Addr {
   {b:Book,a:Addr | b in (addr.a).n }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top