[Haskell] overuse of maybe and [] in prelude and libs
S. Alexander Jacobson
alex at alexjacobson.com
Thu Apr 8 00:41:55 EDT 2004
It feels like the Prelude insists on using [] and
Maybe too much. I keep writing things like this:
foo = foldl union emptySet $ maybe mzero return $ lookup pairs key
goo = maybe emptySet toSomething $ lookup pairs key
which really should look like this:
foo = concat $ lookup pairs key
goo = fmap toSomething $ lookup pairs key
But, even if we don't have a Monadic/Functor Set,
foo should at least be:
foo = foldl union emptySet $ lookup key
In other words, shouldn't Prelude define concat
and lookup as:
concat = foldr mplus mzero -- (Also, see PS)
lookup key [] = mzero
lookup key ((x,y):xyz)
| key == x = return y
| otherwise = lookup key xyz
And if it is a fundamental problem adding
constraints to instances, why not add all
automatically derivable classes as constraints to
all the Prelude classes (esp. Monad and Functor!)
and automatically derive instances of all
derivable classes unless the programmer defines
his/own methods.
-Alex-
PS Shouldn't concat be defined with foldl and not
foldr? Doesn't foldr imply that you can't concat
infinite lists? (I know this is a FAQ, but
where?)
_________________________________________________________________
S. Alexander Jacobson mailto:me at alexjacobson.com
tel:917-770-6565 http://alexjacobson.com
More information about the Haskell
mailing list