dotnet / dotnet/fsharp

Type annotation adjacency warning doesn't consider operator names

Open
#774 6 comments 0 reactions 0 assignees View on GitHub
Area-Compiler-Syntax Bug Impact-Low
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

In this snippet,

``` fsharp
type Digit<'a> = 'a list
type FingerTree<'a> =
| Empty
| Single of 'a
| Deep of Digit<'a> * FingerTree> * 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>.)

If I make the operator a function, instead --

``` fsharp
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.