[Haskell-beginners] list monad question
stephen.tetley at gmail.com
Fri Oct 30 12:27:12 EDT 2009
2009/10/30 Colin Paul Adams <colin at colina.demon.co.uk>:
> Is there a "Bluffer's guide to Haskell"?
Whilst not a bluffers guide, this one contains several dozen flavours
of 'obscurantism' (** add your less pejorative term here **)
Methinks your being a bit hard on the pointfree style, but it does
often diminish an _operation reading_ of the code (you can tell what
the code does from looking at it). So you either have to trust it, or
work it out to some expanded form you are happy with.
For what its worth I came up with this bit of golf which saves a few
keystrokes if you're prepare not to count the helper functions (I
consider them generally useful):
combinations :: Int -> [a] -> [[a]]
combinations = foldr (<:>) [] `oo` replicate
-- Helpers that I like but are not in the libraries
-- | Applicative 'cons'. Equivalent to - liftA2 (:) - but I like
having it around.
-- The monadic version is attributable to a parser library in Clean.
(<:>) :: Applicative f => f a -> f [a] -> f [a]
(<:>) a b = (:) <$> a <*> b
-- | Compose an arity 1 function and an arity 2 function.
-- I call this combinator 'specs' (aka glasses) due to its infix
-- appearance `oo` - I believe fans of Raymond Smullyan's
-- 'To Mock a Mockingbird' call it blackbird...
oo :: (c -> d) -> (a -> b -> c) -> a -> b -> d
oo f g = (f .) . g
More information about the Beginners