[Haskell-cafe] List algorithm
Henning Thielemann
lemming at henning-thielemann.de
Tue May 22 07:11:48 EDT 2007
On Mon, 21 May 2007, Mark T.B. Carroll wrote:
> "Steffen Mazanek" <haskell at steffen-mazanek.de> writes:
>
> > alg 5 1 = [[1]]
> > alg 5 2 = [[1,1],[2]]
> > alg 5 3 = [[1,1,1],[1,2],[2,1],[3]]
>
> Would this be better?
>
> alg n m =
> case signum m of
> -1 -> []
> 0 -> [[]]
> 1 -> [ x : xs | x <- [1..n], xs <- alg n (m - x) ]
This would produce compiler warnings. What about:
case compare m 0 of
GT ->
EQ ->
LT ->
?
More information about the Haskell-Cafe
mailing list