diff --git a/src/pretty_print_types.rs b/src/pretty_print_types.rs index e1355f7e8f..56ee4b7bdc 100644 --- a/src/pretty_print_types.rs +++ b/src/pretty_print_types.rs @@ -28,22 +28,7 @@ fn write_flat_type(flat_type: FlatType, subs: &mut Subs, buf: &mut String, use_p match flat_type { Apply(module_name, type_name, args) => { - let write_parens = use_parens && !args.is_empty(); - - if write_parens { - buf.push_str("("); - } - - buf.push_str(&format!("{}.{}", module_name, type_name)); - - for arg in args { - buf.push_str(" "); - write_content(subs.get(arg).content, subs, buf, true); - } - - if write_parens { - buf.push_str(")"); - } + write_apply(module_name, type_name, args, subs, buf, use_parens) }, EmptyRecord => buf.push_str(EMPTY_RECORD), Func(args, ret) => { @@ -58,6 +43,58 @@ fn write_flat_type(flat_type: FlatType, subs: &mut Subs, buf: &mut String, use_p } } +fn write_apply(module_name: String, type_name: String, args: Vec, subs: &mut Subs, buf: &mut String, use_parens: bool) { + let write_parens = use_parens && !args.is_empty(); + + // Hardcoded type aliases + if module_name == "Num" && type_name == "Num" { + let arg = args.into_iter().next().unwrap_or_else(|| { + panic!("Num did not have any type parameters somehow.") + }); + let arg_content = subs.get(arg).content; + let mut arg_param = String::new(); + + write_content(arg_content, subs, &mut arg_param, true); + + if arg_param == "Int.Integer" { + buf.push_str("Int"); + } else if arg_param == "Float.FloatingPoint" { + buf.push_str("Float"); + } else { + if write_parens { buf.push_str("("); } + + buf.push_str("Num "); + buf.push_str(&arg_param); + + if write_parens { buf.push_str(")"); } + } + } else if module_name == "List" && type_name == "List" { + if write_parens { buf.push_str("("); } + + buf.push_str("List "); + + let arg = args.into_iter().next().unwrap_or_else(|| { + panic!("List did not have any type parameters somehow.") + }); + let arg_content = subs.get(arg).content; + + write_content(arg_content, subs, buf, true); + + if write_parens { buf.push_str(")"); } + } else { + if write_parens { buf.push_str("("); } + + buf.push_str(&format!("{}.{}", module_name, type_name)); + + for arg in args { + buf.push_str(" "); + write_content(subs.get(arg).content, subs, buf, true); + } + + if write_parens { buf.push_str(")"); } + } +} + fn write_fn(args: Vec, ret: Variable, subs: &mut Subs, buf: &mut String, use_parens: bool) { let mut needs_comma = false;