CQCL / guppylang

Pythonic quantum-classical programming language
https://pypi.org/project/guppylang
Apache License 2.0
26 stars 2 forks source link

Prelude: `next` and `iter` #502

Open acl-cqc opened 2 weeks ago

acl-cqc commented 2 weeks ago

i.e. that allow you to manually iterate through a list, rather than using for.

While iter probably just needs a custom checker/compiler that calls __iter__(), next needs to be a bit more complicated to handle the failure case - what does next do to handle __hasnext__ returning false? (I.e. we need either an Optional return type, which would be pythonic, or else make next panic and then provide some way for client to call __hasnext__ first...)

mark-koch commented 3 days ago

Longer term we should just get rid of __hasnext__ and make __next__ return an option type. However, this requires enums or some other ways to encode sums in the language.

See #96