samples: remove receiver.do, fix usable.do
This commit is contained in:
@@ -1,59 +0,0 @@
|
|||||||
#!/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()
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
//! Sample doughlang code
|
//! Sample doughlang code
|
||||||
|
|
||||||
struct Expr {
|
enum Expr {
|
||||||
Atom (f64),
|
Atom (f64),
|
||||||
Op (char, [Expr]),
|
Op (char, [Expr]),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user