Research‎ > ‎

Ella Wilby

F# Compiler - Addition of String Interpolation and Improvement of Type Inference in Various Corner Cases

The community of F# developers are constantly finding areas for improvement. The researcher intends to attempt to implement some of these suggested improvements and then submit a pull request to the GitHub repository for the F# compiler. This will allow for the implementations devised to be reviewed by developers working on the F# compiler and potentially incorporated into the compiler.

The first improvement being the implementation of string interpolation. F# does not currently have any equivalent syntax for string interpolation. Users are therefore limited to the range of C-style *printf functions for string formatting. The *printf functions, however, provide poor readability and so it could be beneficial to have a readable string interpolation syntax in the F# language. The string interpolation implementation will be integrated into the existing printf function and will adhere to it's format specifier syntax.
As such the implementation will allow the user to use string interpolation as follows:
printf "New string interpolation: %(moo)10d. Existing string formatting: %.3f" 42.0

Secondly the researcher intends to improve the type inference of the F# compiler in a few corner cases that have been reported by users to not behave as expected. The number of cases implemented will depend on the difficulty, however, the minimum the researcher aims to achieve is to investigate and implement a stronger and more effective type inference for the following two cases:
  1. The case where type inference is affected by the nature of the one-pass compiler. If a function is not explicitly typed then the type would need to be inferred from the types of the arguments provided. This, however, is prevented by the one-pass compiler as it does not have the capability to look ahead in order to resolve the function type. In some cases the types of the arguments can be inferred from the behavior of the function. In most cases though the user is required to use explicit typing or a work around in order for the function to be valid and typed correctly. The researcher intends to make improvements to the F# compiler so that more cases of functions can be typed implicitly. One such example of such a function which cannot be implicitly typed is:
    (fun x -> x.Length)
    This function declaration is not valid because Length is a property which applies to both strings and Lists and therefore the compiler does not know which type to infer.
  2. The case where the F# compiler fails to handle the type inference in inherited interfaces. When an interface is inherited by another interface and upcasting is performed either implicitly or explicitly the automatic type inference becomes inconsistent. For example being able to implicitly upcast arguments when parameter types are explicitly stated in some cases but not in others. The researcher intends to evaluate and improve upon this where applicable.
Ċ
Ella WILBY,
Mar 29, 2019, 4:11 AM
Comments