Created
February 3, 2017 10:34
-
-
Save TonyLo1/e5fc19d7a60cde5fe3256d26c5114482 to your computer and use it in GitHub Desktop.
How to make more idiomatic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
primitive Inh | |
primitive Sim | |
primitive Imp | |
primitive Equ | |
primitive And | |
primitive Or | |
primitive Not | |
type Op is (Inh|Sim|Imp|Equ|And|Or|Not) | |
type Word is String | |
/* Ideally would like the following but recursive tyoes not allowed | |
type Relation is (Op, Array[Term]) | |
*/ | |
type Term is (Word|Relation) | |
class val Relation | |
let term: (Op, Array[Term]) | |
new create(rel: Op, term': Array[Term]) => | |
term = (rel, term') | |
// Term needs to be sendable and immmutable | |
actor Main | |
let t1: Term = "cat" | |
let t2: Term = "animal" | |
let t3: Term = recover val Relation(Inh, [t1, t2]) end | |
let t4: Term = recover val Relation(Inh, [t1, t2]) end | |
let t5: Term = recover val Relation(Equ, [t3, t3]) end | |
/* Is there a more idiomatic way of achiveing this, without using recovery | |
I want to be able to decalre nested relations like the following: | |
let t6: Term = Relation(Equ, [Relation(Imp, ["dog", "pet"]), Relation(Inh, ["cat", "pet"])]) | |
*/ | |
new create(env: Env) => | |
env.out.print("Done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If relations are normally going to be vals then you can change line 21 to be
new val create(rel: Op, term': Array[Term])
This will make something like
Relation(Inh, [t1, t2])
default to being a
val