Compare commits

...

6 Commits

Author SHA1 Message Date
greg
7c27cace9f Add note 2018-09-17 00:03:29 -07:00
greg
23c54ae186 proc macro feature no longer needed 2018-09-10 21:28:34 -07:00
greg
015840ac38 Get program compileable 2018-09-10 21:28:14 -07:00
greg
b8487aa0d4 Add note from Sergei W. on subtyping 2018-09-10 21:01:56 -07:00
greg
bac5761534 Add a note 2018-09-06 02:12:37 -07:00
greg
926631ba8f Pattern matching experimental code
WIP
2018-08-29 03:00:54 -07:00
3 changed files with 21 additions and 5 deletions

View File

@ -1,6 +1,11 @@
# TODO Items
-make sure to include a :doc command at the REPL that can interface with a lang in a generic way
- a subtype is a situation where the compiler is entitled to add a type conversion in the type-checking process
b/c that type conversion doesn't correspond to a computation
-Sergei W.
*A neat idea for pattern matching optimization would be if you could match on one of several things in a list
ex:

View File

@ -1,6 +1,5 @@
#![feature(trace_macros)]
#![feature(slice_patterns, box_patterns, box_syntax)]
#![feature(proc_macro)]
extern crate itertools;
#[macro_use]
extern crate lazy_static;

View File

@ -58,8 +58,8 @@ pub enum Expr {
#[derive(Debug, Clone)]
pub struct Alternative {
pub tag: Option<usize>,
pub guard: Option<Expr>,
pub bound_vars: Vec<Option<Rc<String>>>, //remember that order matters here
pub guards: Vec<Expr>,
pub bound_vars: Vec<Option<Rc<String>>>, //order here is iconic to order in a tuple-like type, None is equivalent to ignored
pub item: Vec<Stmt>,
}
@ -160,7 +160,7 @@ fn reduce_if_expression(discriminator: &Discriminator, body: &IfExpressionBody,
pat.to_alternative(then_clause, symbol_table),
Alternative {
tag: None,
guard: None,
guards: vec![],
bound_vars: vec![],
item: else_clause,
},
@ -196,6 +196,15 @@ impl Pattern {
SymbolSpec::DataConstructor { index, .. } => index.clone(),
_ => panic!("Bad symbol"),
};
/*
let guards = patterns.iter().map(|p| match p {
});
*/
let guards = unimplemented!();
let bound_vars = subpatterns.iter().map(|p| match p {
Literal(PatternLiteral::VarPattern(var)) => Some(var.clone()),
Ignored => None,
@ -203,7 +212,7 @@ impl Pattern {
}).collect();
Alternative {
tag: Some(tag),
guard: None,
guards,
bound_vars,
item,
}
@ -215,6 +224,9 @@ impl Pattern {
unimplemented!()
},
Ignored => unimplemented!(),
/* "a constant appearing in a pattern can easily be eliminated by replacing it with a variable
* and adding a guard to the equation instead" - Implementation of Functional Programming
* Languages Simon Peyton-Jones, p. 58 */
Literal(lit) => match lit {
PatternLiteral::NumPattern { neg, num } => unimplemented!(),
PatternLiteral::StringPattern(_s) => unimplemented!(),