There are two issues: On the one hand your type must be upper-case, that is UnionType
. Second, you need to define type constructors to be able to create a value of said data
type. So the closest would be e.g.
data UnionType b = Left b | Right (IO b)
Here I chose the arbitrary names Left
and Right
for the constructors, but you can use any you like.
If the Left
/Right
constructors seem familiar to you, that is because Either
uses these by default, and can do exactly the same with a slightly "cheaper" type
synonym:
type UnionType b = Either b (IO b)
Of course in both cases we have to deconstruct the type to get to the actual values of b
and IO b
.
EDIT: As @leftroundabout mentioned, it is not very convenient to define a data
type with type constructors called Left
and Right
, as these constructors are already used with the built in Either
.