Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterate thru compact linear type #119

Open
skaller opened this issue Aug 23, 2018 · 1 comment
Open

Iterate thru compact linear type #119

skaller opened this issue Aug 23, 2018 · 1 comment
Assignees

Comments

@skaller
Copy link
Member

skaller commented Aug 23, 2018

At present you can loop through an integer slice:

for i in 1..10 do ...

and an array with a compact linear index:

  var x = 1,2,3,4;
  var y = (x,x,x,x);
  var z = y :>> (int ^ 16);
  var a = z :>> (int ^ ( 2 * 8));
  for i in a call println$ i; 

but there is no way to iterate through a compact linear type.

@skaller skaller self-assigned this Aug 23, 2018
@skaller
Copy link
Member Author

skaller commented Sep 7, 2018

Partial implementation: this works with new syntax and classes:

instance Eq[5] {
  fun == (x:5,y:5) => caseno x == caseno y;
}
instance Tord[5] {
  fun < (x:5,y:5) => caseno x < caseno y;
}
instance BoundedTordForward[5] {
  fun maxval () => `4:5;
}

instance BoundedTordBidirectional[5] {
  fun minval () => `2:5;
}

instance BoundedTordRandom[5] {
  fun + (x:5,y:5)  => (caseno x + caseno y) :>> 5;
  fun - (x:5,y:5)  => (caseno x - caseno y) :>> 5;
  fun one () => `1:5;
  fun zero () => `0:5;
}


var x = ..[5];
for i in x perform println$ i._strr;

but needs to be generalised so the instance applies to UNITSUM kind, which doesn't yet work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant