Skip to content

Type annotation adjacency warning doesn't consider operator names #774

@frankshearar

Description

@frankshearar

In this snippet,

type Digit<'a> = 'a list
type FingerTree<'a> =
    | Empty
    | Single of 'a
    | Deep of Digit<'a> * FingerTree<Node<'a>> * Digit<'a>

let rec (<<)<'a> (a: 'a) (tree: FingerTree<'a>): FingerTree<'a> =
    match tree with
    | Empty -> Single a
    | Single b -> Deep ([a], Empty, [b])
    | Deep ([b; c; d; e], m, suffix) -> Deep ([a; b], (Node3 (c, d, e)) << m, suffix)
    | Deep (prefix, m, suffix) -> Deep (List.append [a] prefix, m, suffix)

the compiler warns that "Type parameters must be placed directly adjacent to the type name". Presumably that's because the method name is surrounded by ()s.

(I need the <'a> because the function takes a FingerTree<'a> but the recursion takes a FingerTree<Node<'a>>.)

If I make the operator a function, instead --

    let rec addToFront<'a> (a: 'a) (tree: FingerTree<'a>): FingerTree<'a> =
    match tree with
    | Empty -> Single a
    | Single b -> Deep ([a], Empty, [b])
    | Deep ([b; c; d; e], m, suffix) -> Deep ([a; b], addToFront (Node3 (c, d, e)) m, suffix)
    | Deep (prefix, m, suffix) -> Deep (List.append [a] prefix, m, suffix)

-- then everything works.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Compiler-Syntaxlexfilter, indentation and parsingBugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.

    Type

    Projects

    Status

    In Progress

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions