[Haskell-cafe] [Maybe Int] sans Nothings

Alexander Solla alex.solla at gmail.com
Tue May 24 20:38:06 CEST 2011

On Mon, May 23, 2011 at 6:21 PM, Richard O'Keefe <ok at cs.otago.ac.nz> wrote:

> On 24/05/2011, at 5:49 AM, Alexander Solla wrote:
> > There's a library function for it, but also:
> >
> > > filter ((/=) Nothing)
> The problem with that in general is that it only
> applies to [Maybe t] if Eq t, but you don't
> actually _need_ t to support equality.
> filter isJust
> will do the job, where isJust is in Data.Maybe.
Indeed, isJust will do the job.   Sometimes it is acceptable to just use the
tools you know.  For example, filtering a list of (Maybe Int)s.  This is a
balance that is tough to get right.

Personally, I find non-functional values without Eq instances to be
degenerate.  So I really do not mind superfluous Eq constraints.  I would
not hesitate to use filter ((/=) Nothing) in a function whose type has no
free type variables.  It's just a bit of plumbing inside of a more complex

But the point of avoiding unnecessary constraints is a good one, especially
for constraints that constrain more strongly, e.g., Ord.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110524/28c658ff/attachment.htm>

More information about the Haskell-Cafe mailing list