User loginNavigation |
Are extensible records first class patterns?If you have a language with extensible records (like those of Gaster and Jones), and you view functions like a -> Maybe { r } for some row r as patterns, are there practical obstacles that prevent you from extending the environment of a case alternative with the row of the result type of its controlling pattern? I would appreciate pointers to anywhere that this is discussed in the literature, or an explanation of why it is a bad idea. Google hasn't been especially helpful.
-- concrete syntax for records is entirely made-up
wildcard_pattern = const Just {}
-- without first class labels, the compiler would have to make a whole family
-- of declarations like this, one for each variable bound by a pattern
variable_pattern_x val = Just { x := val }
-- same comment applies
as_pattern_x pat val = case pat val of
Just rec -> { x := val, rec }
Nothing -> Nothing
-- I'm not 100% sure that this handles laziness correctly, but you get the idea
-- declarations like this would be automatically generated from the datatype declarations
cons_pattern pat_head pat_tail [] = Nothing
cons_pattern pat_head pat_tail (x:xs) = case pat_head x of
Just rec_head -> case pat_tail xs of
Just rec_tail -> record_join rec_head rec_tail
Nothing -> Nothing
Nothing -> Nothing
nil_pattern [] = Just {}
nil_pattern _ = Nothing
By Douglas McClean at 2009-06-04 02:26 | LtU Forum | previous forum topic | next forum topic | other blogs | 8331 reads
|
Browse archives
Active forum topics |
Recent comments
4 weeks 1 day ago
4 weeks 1 day ago
4 weeks 3 days ago
4 weeks 3 days ago
5 weeks 1 day ago
5 weeks 1 day ago
5 weeks 1 day ago
8 weeks 1 day ago
9 weeks 6 hours ago
9 weeks 11 hours ago