Effective Haskell: Left and Right on page 321

Hi Rebecca,

On page 321 you use Left and Right in the function showLeftRight and I think that you should explain explicitly what Left and Right does because it is not obvious to me how they are used to select the type application.

I mean, I can see in your example that Left is used to select the first type application, and Right the second one, (I THINK), but I am still unsure.

Hi! Thanks for pointing this out. I’ll update the example with a bit of extra clarification. Just to help out here, until the next update is released, I’ll explain a bit more.

Either has two type parameters, so we’d say something like Either Int Float or Either String Bool. Either has two constructors, Left and Right. The Left constructor will only ever have a value of the left type parameter (Int or String from our examples), and the Right constructor will only ever have a value of the right type parameter (Float or Bool).

Our showLeftRight example will return an Either value, so we need to pick types for each of it’s two type parameters, but we’ll only ever actually need to make a value for one or the other, so we can ignore the one that we happen to know we won’t need to use.