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

Document iftype #393

Open
SeanTAllen opened this issue Jun 29, 2019 · 3 comments
Open

Document iftype #393

SeanTAllen opened this issue Jun 29, 2019 · 3 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@SeanTAllen
Copy link
Member

It's been around for a long time as a "beta" sort of feature. It's required for some programs. At this point, I think we need to document it so that general users can access, use, and push our understanding of its shortcomings.

rhagenson added a commit that referenced this issue Apr 25, 2020
First mention of iftype for progress toward #393
@rhagenson
Copy link
Member

Looking at the tests on this directive the following clauses are recognized:

Standard if:

iftype A <: C then 
  ... 
end

With capability:

iftype A <: C box then 
  ... 
end

Tuple:

iftype (A, B) <: (C1, C2) then 
  ... 
end

Cardinality of tuples must match -- i.e., there is no deduplication via (A, B) <: C or nesting via A <: (C1, C2)

Recursive:

iftype A <: T[A] then 
  ... 
end

Mutually recursive:

iftype (A, B) <: (T[B], T[A]) then 
  ... 
end

Nested:

iftype A <: T then 
  iftype A <: C then 
    ... 
  end
end

Replace type args:

iftype X <: A #read then 
  ... 
end

@rhagenson
Copy link
Member

My opinion on where this might best fit in the tutorial currently is Equality in Pony in a section called "Type Equality" or something similar. iftype checks both type equality and subtype relationship so A <: A is always true.

Forewarning: "the subtype in an iftype condition must be a type parameter or a tuple of type parameters" so the following does not pass the compiler:

primitive P
type T is P

actor Main
  new create(env: Env) =>
    iftype T <: P then
      None
    end

nor does replace the iftype expression with iftype P <: P then ... end

@EpicEric
Copy link
Contributor

Also important to note that iftype has an else clause.

@rhagenson rhagenson added the good first issue Good for newcomers label Dec 16, 2020
@SeanTAllen SeanTAllen added the help wanted Extra attention is needed label Feb 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants