Bottom / undefined value in F #?

Haskell has a convenient undefined value that can be used as a stub for still defined functions / paths in the code. Is there anything similar in F #?

+6
source share
3 answers

To be specific, you can define such a value as follows:

let undefined<'T> : 'T = failwith "Not implemented yet" let stub1 (x : int) : float = undefined let stub2 (x : 'T) : 'T = undefined 

Beware that the F # score is strict. If you bind undefined to a top-level value, it throws an exception during evaluation.

+11
source

I think,

 failwith "Not implemented" 

will be pretty much equivalent

+6
source

A more specific and convenient way for .NET

 let undefined<'T> : 'T = raise (NotImplementedException()) 

allows you to skip message input and still distinguish this exception from others in the catch block or stack trace.

+5
source

Source: https://habr.com/ru/post/959196/


All Articles