bracketOnError, while, forever
Malcolm Wallace
Malcolm.Wallace at cs.york.ac.uk
Wed Feb 9 08:33:37 EST 2005
"Simon Marlow" <simonmar at microsoft.com> writes:
> >> comparing :: (Ord a) => (b -> a) -> b -> b -> Ordering
> >> comparing p x y = compare (p x) (p y)
>
> sortBy (comparing fst)
>
> is just too cute not to have. Any objections?
Looks good to me.
> >> readM :: (Monad m, Read a) => String -> m a
>
> Also subsumes System.IO.readIO. Looks useful to me.
Yup.
> >> selections :: [a] -> [(a,[a])]
> >> selections [] = []
> >> selections (x:xs) = (x,xs) : [ (y,x:ys) | (y,ys) <- selections xs ]
> >>
> >> permutations :: [a] -> [[a]]
> >> permutations [] = [[]]
> >> permutations xs =
> >> [ y : zs
> >> | (y,ys) <- selections xs
> >> , zs <- permutations ys
> >> ]
Here's another one. I'm not sure what to call it, since 'permutation'
means something subtly different.
-- Given a list of alphabets, return all possible strings with one
-- symbol chosen from each alphabet respectively.
permute :: [[a]] -> [[a]]
permute [] = [[]]
permute (xs:xss) = [ f:fs | f <- xs, fs <- permute xss ]
Regards, Malcolm
More information about the Libraries
mailing list