Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

f#

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?

like image 208
mazin Avatar asked Aug 25 '26 01:08

mazin


1 Answers

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]
like image 163
Gus Avatar answered Aug 27 '26 15:08

Gus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!