effekt
effekt copied to clipboard
Show instances for ground types
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})"
}
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()))))
Since it is a "user defined" function, you need to call it with App, not PureApp