Skip to content

Conversation

mattisboeckle
Copy link
Contributor

Implement new Core -> Core Phase which
synthesizes show definitions for any type based on ground show definitions

For example

type MaybeInt {
  Nothing()
  Just(x: Int)
}

could generate something along the lines of

def show(value: MaybeInt): String = value match {
  case Nothing() => "Nothing"
  case Just(x: Int) => "Just(${x.show})"
}

@mattisboeckle
Copy link
Contributor Author

The current implementation can already generate the following core code for

type MaybeInt {
  Nothing()
  Just(x: Int, y: Int)
}
def myshow_3970(value_3971: MaybeInt_3714) = {
  def b_k0_3972() = return "Nothing"
  def b_k1_3973(x_3722: Int_389, y_3723: Int_389) = return infixConcat_39("Just(", infixConcat_39(show_15(x_3722), infixConcat_39(", ", infixConcat_39(show_15(y_3723), ")"))))
  val v_r_3974: String_394 = value_3971 match {
    case Nothing_3718 { () => 
      b_k0_3972()
    }
    case Just_3719 { (x_3722: Int_389, y_3723: Int_389) => 
      b_k1_3973(x_3722, y_3723)
    }
  };
  return v_r_3974
}

but when being called in main like this

let tmp_3960 = make MaybeInt_3714 Just_3719(42, 45)
let tmp_3963 = myshow_3970(tmp_3960)
let tmp_3964 = println_1(tmp_3963)

the compiler fails in Transformer with
Unsupported expression: PureApp(BlockVar(myshow,Function(List(),List(),List(Data(MaybeInt,List())),List(),Data(String,List())),Set()),List(),List(ValueVar(tmp,Data(MaybeInt,List()))))

@b-studios
Copy link
Collaborator

Since it is a "user defined" function, you need to call it with App, not PureApp

val TString = ValueType.Data(builtins.StringSymbol, Nil)
val TDouble = ValueType.Data(builtins.DoubleSymbol, Nil)

val Builtins = List(TUnit, TInt, TChar, TByte, TBoolean, TString, TDouble)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick:

Suggested change
val Builtins = List(TUnit, TInt, TChar, TByte, TBoolean, TString, TDouble)
val builtins = List(TUnit, TInt, TChar, TByte, TBoolean, TString, TDouble)

also delete old show functions, this works for all non-generic data types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants