[Haskell] Annoying naming clashes

Esa Pulkkinen esa.pulkkinen at kotiposti.net
Tue Jun 15 13:38:45 EDT 2004

In message <OFF88B2A02.2232ECC3-ON86256EB4.0054E974-86256EB4.00559618 at combined.
com>, Ben.Yu at combined.com writes:
>it is nice to use 'maybe', 'either' functions. However, with data types
>with more than 2 constructors, using such function tends to be tedious than
>pattern match, where, you can pick specific constructors of interest.
>And in order to use pattern match, I have to expose my constructors.

You don't necessarily need to expose the constructors even in that case.
Often you can expose functions that return 'Maybe a' for some suitably
chosen 'a' instead of the constructor itself. Then you can pattern match
with e.g. the following syntax:

f x | Just(y) <- matchZ x = y + 1

And the Maybe monad works beautifully for combining such functions into
larger pattern matchers. The point with having abstraction is to
actually expose only higher level operations. 

Of course, this doesn't negate any other reasons you might have for
exposing the constructors [e.g. if the data type is used to represent an
interface], but if you want to build abstract data types, those should
be at higher level of abstraction than the concrete types.
  Esa Pulkkinen

More information about the Haskell mailing list