Question about Pattern match(es) are non-exhaustive error
- cohen.avrahamOP
G-d willing
Hello,
Following to my previous post, I am using the--ghc-option=-Wincomplete-uni-patternsin mybuild-options
This time I am getting an error on the following code:testCheckConstraintsAgainst : Script () testCheckConstraintsAgainst = do let record1 = Record 2 True (-1) record2 = Record (-1) False 2 record3 = Record 1 True 0 Right b = typecheckAgainst @Record $ var "record.foo" `mul` 1 Right b' = typecheckAgainst @Record $ var "record.foo" `minus` 1The error message is:
Pattern match(es) are non-exhaustive In a pattern binding: Patterns not matched: (Left _)Since I am new to Daml, I know to use
RightandLefton acaseswitch, but I am not sure how it works when I just type it inside aletcommand. - cocreature
I think your best option here is to do a
caseon the rightlet b = case typecheckAgainst @Record $ var "record.foo" `mul` 1 of Right b -> b Left e -> doSomething - cohen.avraham
Thanks for the reply but this is still not good enough.
Keep in mind that I am using theWincomplete-uni-patternsbuild option.
Basically after the code I attached, there is usage for b & b’. So in that case b is not defined anymore as the right value, but the Either. And if I try to fix it by using Right whenever we use it, I am getting that error message again (Pattern match(es) are non-exhaustive In a pattern binding: Patterns not matched: (Left _)
So, I am not sure how to get rid of that loop. - cocreature
What do you want to happen in the
Leftcase? Can you share the code afterwards that uses it? - cohen.avraham
Well the other 2 lines after that are:
dynamicConstraint = mkConstraintUnsafe @Record (var "record.b" `gt` 0) "b is positive" [mkBinding "b" b] updatedConstraint = updateConstraintBindingsUnsafe dynamicConstraint [mkBinding "b" b'] - cocreature
Can you share what you expect to happen if you get a
Left? - cohen.avraham
Well, I was offered a solution which worked well for me at this point and it was adding the following code:
testTypedExpr : Either TypecheckErr (TypedExprAgainst a) -> (TypedExprAgainst a) testTypedExpr val = case val of Right result -> result Left _ -> error "Error"and the previous 2 lines I changed to:
b = testTypedExpr $ typecheckAgainst @Record $ var "record.foo" `mul` 1 b' = testTypedExpr $ typecheckAgainst @Record $ var "record.foo" `minus` 1 - cocreature
Isn’t that exactly the
casesolution I suggested? I think I don’t understand why that did not work for you. - cohen.avraham
G-d willing
No it is not the same since using the
casewill returnEithervalue and not theRightvalue. And since I am using the returned value later on, it won’t work.
That will force me again to use the Right and Left on the same returned value - so it is kind of an infinite loop. - cocreature
I don’t think that should be true. If you look at my example, note that I also extract the value from the Either
Right b -> bWhat you say would apply if we had
Right b -> Right b - cocreature
If you have a concrete example and an error message, I’m happy to take a look.