You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An idea on how to look at parameterized patterns. Currently Asteroid supports parameterized patterns via variables read from the environment,
Asteroid Version 2.0.1alpha
(c) University of Rhode Island
Type "asteroid -h" for help
Press CTRL-D to exit
ast> let p = pattern %integer.
ast> let pair = pattern (x:*p,y:*p).
ast> let q:*pair = (1,2). -- here pair is a pair of integer values
ast> q
(1,2)
ast> let p = pattern %real. -- now pair is a pair of real values
ast> let q:*pair = (1,2).
error: pattern match failed: conditional pattern match failed
ast> let q:*pair = (1.1,2.2).
ast>
This is very clumsy and prone to programming errors...think dynamically scoped functions. A nice way would be to actually have have parameters on the pattern. Something like this perhaps,
ast> let p = pattern %integer.
ast> let pair = pattern with a match (x:*a,y:*a).
ast> let q:*pair(p) = (1,2). -- here pair is a pair of integer values
ast> q
(1,2)
or in more concise form,
ast> let pair = pattern with a match (x:*a,y:*a).
ast> let q:*pair(pattern %integer) = (1,2). -- here pair is a pair of integer values
ast> q
(1,2)
ast> let q:*pair(pattern %real) = (1.1,2.2). -- here pair is a pair of real values
ast> q
(1.1,2.2)
The text was updated successfully, but these errors were encountered:
We cannot use juxtaposition as a way to parameterize patterns, it makes the language too ambiguous due to the confusion with function application. We can adopt the generics notation here,
ast> let pair = pattern<a> (x:*a,y:*a).
ast> let q:*pair<pattern %integer> = (1,2). -- here pair is a pair of integer values
ast> q
(1,2)
ast> let q:*pair<pattern %real> = (1.1,2.2). -- here pair is a pair of real values
ast> q
(1.1,2.2)
An idea on how to look at parameterized patterns. Currently Asteroid supports parameterized patterns via variables read from the environment,
This is very clumsy and prone to programming errors...think dynamically scoped functions. A nice way would be to actually have have parameters on the pattern. Something like this perhaps,
or in more concise form,
The text was updated successfully, but these errors were encountered: