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

Idea: add feature for compile-time casts #3336

Closed
fridis opened this issue Jul 9, 2024 · 3 comments
Closed

Idea: add feature for compile-time casts #3336

fridis opened this issue Jul 9, 2024 · 3 comments
Labels
base library related to the Fuzion base library enhancement New feature or request

Comments

@fridis
Copy link
Member

fridis commented Jul 9, 2024

If we defined

  cast(T type, v T) => v

we could use this to force the compiler to perform its casting or tagging magic to a value, e.g.,

  l := cast (list u8) nil          
  f := cast f32 0
  b := cast bool TRUE 
  a,b,c is
  abc := if cc then 
      cast (a|b|c) a
    else
      cast (a|b|c) b
  match abc
    a => say "a"
    b => say "b"
    c => say "c"

instead of

  l list u8 :=  nil          
  f f32 := 0
  b bool := TRUE 
  a,b,c is
  abc a | b | c := if cc then 
      a
    else
      b
  match abc
    a => say "a"
    b => say "b"
    c => say "c"

Are there any cases where this is useful? This could at least be used an example in the tutorial to explain the compiler magic that happens to adapt an expression to match the target type.

@fridis fridis added enhancement New feature or request Fuzion language related to the language, syntax, etc base library related to the Fuzion base library and removed Fuzion language related to the language, syntax, etc labels Jul 9, 2024
@michaellilltokiwa
Copy link
Member

michaellilltokiwa commented Jul 9, 2024

Turns out we already have a feature with the same signature as cast: id(T type, x T) T => x

@michaellilltokiwa
Copy link
Member

@fridis can this be closed?

@maxteufel
Copy link
Collaborator

let's close this since the id feature you mentioned exists already

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
base library related to the Fuzion base library enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants