Q:

Pattern matching a combination Maybe and Either

How to match pattern
Maybe (Either (Int, String) String)

I need to write function with such kind of input and how it is possible to parse such input?

A:

The Maybe a type has the patterns Just a and Nothing. The Either a b type has the patterns Left a and Right b. So a value of type Maybe (Either (Int, String) String) can match the following patterns:

Nothing
Just (Left (x,y)) where x is an Int and y is a String
Just (Right z) where z is a String.

A:

f :: Maybe (Either (Int, String) String) -> <SOMETHING>
f x = case x of
    Just (Left (i, s)) -> <...>
    Just (Right s) -> <...>
    Nothing -> <...>

