Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 2592

Variant with generic "mysterious" behaviour

$
0
0

@tsnobip you’ve connected the dots with these two:

  • let foo : 'a = 1 and…
  • all branches of a switch need to return the same type.

Thank you for pointing this out!

Can I say that I “trigger” the unification by handling the value of type expect<'t> within the Http.get function? This is because the compiler can infer the types by values and because there are two branches (expectJson and expectText), one of which takes a generic 't, the compiler “narrows” it down to the first most concrete type, which is string, isn’t it?

If I add another variant, say ExpectInt(int => result<int, string>) and handle it in my switch like so ExpectInt(val) => val(42) // decoding an int, then the compiler complains about this line with int vs string.


Viewing all articles
Browse latest Browse all 2592

Trending Articles