question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`'a option` generates `null`

See original GitHub issue

What is the best way to test Option values? I can use obj.ReferenceEquals to make sure the Option isn’t null, but it just doesn’t seem right.

// The type ''a option' does not have 'null' as a proper value
let f (x : 'a option) = isNull x

// Ok, passed 100 tests (99% <null>).
[<Property>]
let testOption (x : int option) =
    obj.ReferenceEquals(x, null) ==> Prop.collect x true

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
kurtschelfthoutcommented, Apr 11, 2016

F# has eager evaluation, so FsCheck can’t prevent it from evaluating the right hand side of ==> even if the left hand side is false. You should be able to wrap the right side in lazy to prevent this:

[<Property>]
let ``If set has length gteq 0`` (t : T) =
    (t.X.IsSome && t.X.Value <> null) ==>
        lazy (let i = (t.X.Value.Length) in i >= 0)
    |> Prop.collect t
0reactions
simendsjocommented, Apr 12, 2016

Of course! Thanks 😃 The bug was in my head as usual.

Read more comments on GitHub >

github_iconTop Results From Across the Web

r - Setting an option to NULL
Workaround: nest the (potentially NULL ) value in a list and use that: options(TEST = list(NULL)) getOption("TEST")[[1]] # [1] NULL ...
Read more >
Null, Undefined and Option | ReScript Language Manual
It means "a value of type option is either None (representing nothing) or that actual value wrapped in a Some". Note how the...
Read more >
Angular <option> for null not working in Visualforce
In salesforce.com Visualforce pages the default option value for null is not being displayed. I have a very simple select component with one ......
Read more >
Null Checking | ReSharper Documentation
Generate null checks for exceptions and assertions · Press Alt Enter on a parameter or expression and choose the corresponding context action:.
Read more >
Null Values - F# | Microsoft Learn
Instead of null, with an F# option type, you use the option value None if there is no object. You use the option...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found