mazin
mazin

Reputation: 395

F# has a discrepancy between func `lambda` and `lambda` |> func

I'm using the FSharpPlus library and there is a discrepancy between

#r "nuget: FSharpPlus"
open FSharpPlus

memoizeN (fun x y -> x,y)       // error FS0073: internal error: recursive class hierarchy (detected in TypeFeasiblySubsumesType), ty1 = MemoizeN

(fun x y -> x,y) |> memoizeN    // OK

Why does this happen, and is there a way to use the former?

Upvotes: 3

Views: 96

Answers (1)

Gus
Gus

Reputation: 26184

It's not because of the lambda, this is kind of a corner type inference case.

F# type inference works from left to right, so in some cases it's not able to infer the correct type of a generic function, unless the type information of its argument is already inferred.

A simpler case could be this:

let x = (fun lst -> lst.Length) [0]

Upvotes: 1

Related Questions