Before this is noted as a duplicate: I know that this question is related to various questions about compilation errors when using unit as a type argument. Some examples:
unit
They all face a problem like this:
type Interface<'a> = abstract member MyFunc : unit -> 'a let implementingInstance = { new Interface<_> with member __.MyFunc () = () } // Compiler error!
From what I understand, the code does not compile, because the unit return function compiles with return voidinternally, which is an additional CLI feature, not a type.
void
However! The following seems to suit the compiler:
type RecordVersion<'a> = { MyFunc : unit -> 'a } let recordInstance = { MyFunc = ignore }
, ignore lambda let.
ignore
let
. ( F #, , .)
API-, . , . , . , F # .
? API, ? ( , , .)
, , , unit, .NET- void .NET( , , ). , void, , true unit CLR.
- , unit CLR ( CLR unit void). , , , , , , unit ( unit ), , , .
, F # . (, T<'unit>) Unchecked.defaultof<'unit> (), . T T<unit>, .
T<'unit>
Unchecked.defaultof<'unit>
()
T
T<unit>
, , ( AFAIK ) F # IL-, void. Microsoft.FSharp.Core.FSharpFunc<unit, unit> (aka unit -> unit), "" - void.
Microsoft.FSharp.Core.FSharpFunc<unit, unit>
unit -> unit
, . :
type Interface<'a> = // Note the parentheses to make this member a property rather than a method abstract member MyFunc : (unit -> 'a) let implementingInstance = { new Interface<_> with // Must use an explicit `fun () ->` instead of a method arg list member __.MyFunc = fun () -> () }
, , , (()) (.. unit, ). , :/
(())
Source: https://habr.com/ru/post/1659050/More articles:Spring testing and JsonPath issue - spring-mvcZingChart does not display all words in wordcloud - javascriptTypescript, D3 and powerBI: How do I get typescript to talk with D3 v4? - typescriptDraw a line using the d3.js library in the Power BI visual representation - plotOracle Concurrency Control with Delphi7 - c #Compute `cumsum` by starting the signal value - rF # async / wait in viewmodel - f #Python wrong result - pythoniOS 10 - AVPlayer displays a black screen when playing video - iosSafari animation (keyframes and transform) sets the wrong position - cssAll Articles