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.

Bottom Exception when first Either in LINQ from expression is in Left state

See original GitHub issue

First up, this is an awesome Library and it is making me love C# again.

I have noticed an issue when using nested Monads in LINQ from select statements.

In my case I’m nesting an Either inside a Task, however if the unwrapping is done in a single LINQ step a Bottom Exception occurs.

So given:

var failableTask = fun((Either<string, int> value) =>
    Task.Run(() =>
    {
        Thread.Sleep(3000);
        return value;
    }));

The following will work as expected:

var result = await from a in failableTask(34)
                   from b in failableTask("This will work as expected")
                   select a + b;

However, if the first Either is in it’s Left state a Bottom Exception occurs:

var result = await from a in failableTask("This will cause a Bottom Exception")
                   from b in failableTask(3)
                   select a + b;

If I unwrap the nested Monads separately it works as expected:

var result = await from a in failableTask("This will work as expected")
                   from b in failableTask(3)
                   select from a1 in a
                          from b1 in b
                          select a1 + b1;

I haven’t yet explored what functions are called under the hood to debug this further just yet.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
louthycommented, Mar 27, 2018

This issue is fixed in v2.2.17-beta

1reaction
louthycommented, Jul 27, 2017

Ok, leave it with me I’ll put in some more tests.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The LINQ expression could not be translated. Either rewrite ...
The issue is that you are trying to do a string.Contains within an Any expression which EF will choke on trying to compose...
Read more >
The 10 Most Common Mistakes in C# Programming
Common C# Programming Mistake #5: Failing to consider the underlying objects in a LINQ statement.
Read more >
Invalidoperationexception: the LINQ expression
Hi, I have the message System.InvalidOperationException: The LINQ expression 'DbSet<Developer>() .Where(d => d.
Read more >
Functional Programming in C# - Expressions, Option, Either
Part 1 summarised how I started in FP in C# by learning LINQ and trying Project Euler ... Expressions first helps keep the...
Read more >
Dixin's Blog - EntityFramework.Functions: Code First ...
The difference is, it works in LINQ to Entities queries, but cannot be called directly. As a result, its body will never be...
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