Initial Commit
This commit is contained in:
59
samples/receiver.do
Normal file
59
samples/receiver.do
Normal file
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env dough
|
||||
|
||||
/*
|
||||
Type = "type" Identifier (<Generics>)? '=' TypeSpec
|
||||
|
||||
TypeSpec = (
|
||||
| Identifier
|
||||
| str (StructField),* uct
|
||||
| tup (TupleField),* le
|
||||
| cho (ChoiceField),* ice
|
||||
)
|
||||
|
||||
StructField = Identifier ':' TypeSpec
|
||||
TupleField = TypeSpec
|
||||
EnumField = Identifier ('(' TypeSpec ')')?
|
||||
|
||||
*/
|
||||
|
||||
// Product type with named fields
|
||||
type Product<T> = {
|
||||
a: i32,
|
||||
b: T,
|
||||
c: {
|
||||
d: i32,
|
||||
e: i32,
|
||||
f: []
|
||||
},
|
||||
};
|
||||
|
||||
// Product type with indexed fields
|
||||
type Tuple<T, U> = (
|
||||
i32,
|
||||
T,
|
||||
U,
|
||||
);
|
||||
|
||||
// Choice/Sum type, which degrades to enumeration
|
||||
type Sum = Nothing | A(Product) | B(Tuple) ;
|
||||
|
||||
|
||||
// Kotlin style?
|
||||
type <V> Option = {
|
||||
None,
|
||||
Some(V)
|
||||
}
|
||||
|
||||
// fucked up?
|
||||
type Option<V> (None | Some(V));
|
||||
|
||||
fn x(self: &Sum) -> Product {
|
||||
match self {
|
||||
Nothing | B(_) => panic(),
|
||||
A(value) =>
|
||||
}
|
||||
}
|
||||
|
||||
fun x(a: T<A>) -> A {
|
||||
a.get()
|
||||
}
|
||||
Reference in New Issue
Block a user