<div dir="ltr"><div>Hi Philippe,</div><div><br></div><div>You should probably split directly on `x` in the left-hand side instead:</div><div><br></div><div>getStringOrInt : (x : Bool) → StringOrInt x<br>getStringOrInt true = 94<br>getStringOrInt false = "Ninety four"<br></div><div><br></div><div>or use `case_return_of_` as suggested by Ulf. However, there is a trick that I'm quite fond of that you can use to make it work even with the non-dependent `case_of_`:</div><div><br></div><div>data Is {ℓ} {A : Set ℓ} : A → Set ℓ where<br>  ⌊_⌋ : (x : A) → Is x<br><br>getStringOrInt : (x : Bool) → StringOrInt x<br>getStringOrInt x = case ⌊ x ⌋ of λ where<br>  ⌊ true  ⌋ → 94<br>  ⌊ false ⌋ → "Ninety Four"</div><div><br></div><div>The reason this works is that by using the `Is` datatype, Agda keeps the connection between the first argument of the `case_of_` and the original `x`, so when you case split in the `λ where` Agda also refines the original argument `x` (actually Agda treats both of them as the same variable).</div><div><br></div><div>-- Jesper<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Apr 16, 2020 at 9:26 AM Ulf Norell <<a href="mailto:ulf.norell@gmail.com">ulf.norell@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div>The problem is that the `case_of_` function is non-dependent (the type of the branches cannot depend of the value you case on).</div><div>You can use `case_return_of_` instead if you need a dependent match:</div><div><br></div><div><span style="font-family:monospace">getStringOrInt : (x : Bool) → StringOrInt x<br>getStringOrInt x = case x return StringOrInt of λ where<br>  true → 94<br>  false → "Ninety Four"</span></div><div><br></div><div>However, the "correct" way to write the function is</div><div><br></div><div><span style="font-family:monospace">getStringOrInt : (x : Bool) → StringOrInt x<br>getStringOrInt true = 94<br>getStringOrInt false = "Ninety Four"</span></div><div><br></div><div>/ Ulf<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Apr 16, 2020 at 8:35 AM Philippe de Rochambeau <<a href="mailto:phiroc@free.fr" target="_blank">phiroc@free.fr</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div>Hello,</div><div><br></div><div>when I load the following module, </div><div><br></div><div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:Menlo;color:rgb(237,97,27)"><div style="margin:0px;font-stretch:normal;line-height:normal;color:rgb(194,0,255)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(237,97,27)">open</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(237,97,27)">import</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures">Agda.Builtin.Bool</span></div><div style="margin:0px;font-stretch:normal;line-height:normal;color:rgb(194,0,255)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(237,97,27)">open</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(237,97,27)">import</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures">Agda.Builtin.Nat</span></div><div style="margin:0px;font-stretch:normal;line-height:normal;color:rgb(194,0,255)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(237,97,27)">open</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(237,97,27)">import</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures">Agda.Builtin.String</span></div><div style="margin:0px;font-stretch:normal;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">open</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures">import</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(194,0,255)">Function</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures">using</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(83,83,83)">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(69,0,255)">case_of_</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(83,83,83)">)</span></div><div style="margin:0px;font-stretch:normal;line-height:normal;color:rgb(0,0,0);min-height:21px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-stretch:normal;line-height:normal;color:rgb(69,0,255)"><span style="font-variant-ligatures:no-common-ligatures">StringOrInt</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(83,83,83)">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(83,83,83)">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">x </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(83,83,83)">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures">Bool</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(83,83,83)">)</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(83,83,83)">→</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures">Set</span></div><div style="margin:0px;font-stretch:normal;line-height:normal;color:rgb(69,0,255)"><span style="font-variant-ligatures:no-common-ligatures">StringOrInt</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> x  </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(83,83,83)">=</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures">case</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> x </span><span style="font-variant-ligatures:no-common-ligatures">of</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(83,83,83)">λ</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(237,97,27)">where</span></div><div style="margin:0px;font-stretch:normal;line-height:normal;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(45,150,30)">true</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(83,83,83)">→</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(69,0,255)">Nat</span></div><div style="margin:0px;font-stretch:normal;line-height:normal;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(45,150,30)">false</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(83,83,83)">→</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(69,0,255)">String</span></div><div style="margin:0px;font-stretch:normal;line-height:normal;color:rgb(0,0,0);min-height:21px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-stretch:normal;line-height:normal;color:rgb(69,0,255)"><span style="font-variant-ligatures:no-common-ligatures">getStringOrInt</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(83,83,83)">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(83,83,83)">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">x </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(83,83,83)">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures">Bool</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(83,83,83)">)</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(83,83,83)">→</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures">StringOrInt</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> x</span></div><div style="margin:0px;font-stretch:normal;line-height:normal;color:rgb(69,0,255)"><span style="font-variant-ligatures:no-common-ligatures">getStringOrInt</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> x </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(83,83,83)">=</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures">case</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> x </span><span style="font-variant-ligatures:no-common-ligatures">of</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(83,83,83)">λ</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(237,97,27)">where</span></div><div style="margin:0px;font-stretch:normal;line-height:normal;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">  </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(45,150,30)">true</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(83,83,83)">→</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(194,0,255)">94</span></div><div style="margin:0px;font-stretch:normal;line-height:normal;color:rgb(180,36,25)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">  </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(45,150,30)">false</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(83,83,83)">→</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="text-decoration:underline;font-variant-ligatures:no-common-ligatures">"Ninety Four"</span></div><div><span style="text-decoration:underline;font-variant-ligatures:no-common-ligatures"><br></span></div></div></div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:Menlo;min-height:21px"><br></div><div style="margin:0px;font-stretch:normal;line-height:normal;min-height:21px">… I get this error message:</div><div style="margin:0px;font-stretch:normal;line-height:normal;font-family:Menlo;min-height:21px"><br></div><div style="margin:0px;font-stretch:normal;line-height:normal;min-height:21px"><div style="font-family:Menlo;margin:0px;font-stretch:normal;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">String != Nat</span></div><div style="font-family:Menlo;margin:0px;font-stretch:normal;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">when checking that the expression "Ninety Four" has type Nat</span></div><div style="font-family:Menlo;margin:0px;font-stretch:normal;line-height:normal"><br></div><div style="margin:0px;font-stretch:normal;line-height:normal">Do lambdas only return one data type (in this case, Nat)?</div><div style="margin:0px;font-stretch:normal;line-height:normal"><br></div><div style="margin:0px;font-stretch:normal;line-height:normal">Cheers,</div><div style="margin:0px;font-stretch:normal;line-height:normal"><br></div><div style="margin:0px;font-stretch:normal;line-height:normal">Philippe</div><div style="font-family:Menlo;margin:0px;font-stretch:normal;line-height:normal"><br></div><div style="font-family:Menlo;margin:0px;font-stretch:normal;line-height:normal"><br></div></div></div>_______________________________________________<br>
Agda mailing list<br>
<a href="mailto:Agda@lists.chalmers.se" target="_blank">Agda@lists.chalmers.se</a><br>
<a href="https://lists.chalmers.se/mailman/listinfo/agda" rel="noreferrer" target="_blank">https://lists.chalmers.se/mailman/listinfo/agda</a><br>
</blockquote></div></div>
_______________________________________________<br>
Agda mailing list<br>
<a href="mailto:Agda@lists.chalmers.se" target="_blank">Agda@lists.chalmers.se</a><br>
<a href="https://lists.chalmers.se/mailman/listinfo/agda" rel="noreferrer" target="_blank">https://lists.chalmers.se/mailman/listinfo/agda</a><br>
</blockquote></div>