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

Support optional type #45

Open
tmteam opened this issue May 30, 2022 · 0 comments
Open

Support optional type #45

tmteam opened this issue May 30, 2022 · 0 comments
Labels
Brutal Can take a lot of time and health. Is your life long enough? Definitely nice to have Syntax Syntactic and semantic improvements and sugars Tic Type inference calculator has to be changed

Comments

@tmteam
Copy link
Owner

tmteam commented May 30, 2022

type optional-- : T | none

  1. assume we have 'none' constant of type 'NONE'
  2. optional type T is type that can be either T or NONE
  3. T can be converted to optional--
  4. default of optional-- equals 'none'
    optional:
  5. 'any' is nullable by its nature (???)
use 'none' const and aliasless 'none' type with default value of none

a = none
b = if(a == none) "nothing" else "anything" #nothing

#optional-<T>- type can be converted to any. T can be converted to optional-<T>- type

a = if(true) 42 else none # a is optional-<T>-
b:any = a # is ok
c:int = a # fails
#optional can be used only in if expression

a = if(true) 42 else none 

b = if(a==none) default else a+31 
c = if(a!=none) a+31 else default

'otherwise' function can be used to return fallback value if the origin value is in fallback

#sketch
otherwise(a, defaultValue) = 
  if(a == none) defaultValue
  else a

#sketch
otherwise(a, defaultValue) = 
  if(a == none) default
  else a.notNone()

#sketch
notNone(a) = 
  if(a == none) error
  else a

@tmteam tmteam changed the title support optional values Support optional type May 30, 2022
@tmteam tmteam added Brutal Can take a lot of time and health. Is your life long enough? Syntax Syntactic and semantic improvements and sugars labels May 30, 2022
@tmteam tmteam added this to the Nfun meta language milestone May 30, 2022
@tmteam tmteam added the Tic Type inference calculator has to be changed label May 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Brutal Can take a lot of time and health. Is your life long enough? Definitely nice to have Syntax Syntactic and semantic improvements and sugars Tic Type inference calculator has to be changed
Projects
None yet
Development

No branches or pull requests

1 participant