Proposal: making inits and tails less strict
Don Stewart
dons00 at gmail.com
Thu Mar 17 21:09:19 CET 2011
Could the strictness properties be stated in the specification (i.e.
include some QuickCheck properties that define the strictness)
On Thu, Mar 17, 2011 at 12:25 PM, Bas van Dijk <v.dijk.bas at gmail.com> wrote:
> Hello,
>
> I would like to propose making inits and tails less strict:
>
> inits :: [a] -> [[a]]
> -inits [] = [[]]
> -inits (x:xs) = [[]] ++ map (x:) (inits xs)
> +inits xs = [] : case xs of
> + [] -> []
> + x:xs -> map (x:) (inits xs)
>
> tails :: [a] -> [[a]]
> -tails [] = [[]]
> -tails xxs@(_:xs) = xxs : tails xs
> +tails xxs = xxs : case xxs of
> + [] -> []
> + _:xs -> tails xs
>
> Having a lazier inits allows the elegant:
> nats = map length (inits nats)
> which loops for the current definition. This definition was due to John Tromp:
> http://www.mail-archive.com/haskell@haskell.org/msg21044.html
>
> Discussion deadline: 2 weeks.
>
> Regards,
>
> Bas
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
>
>
More information about the Libraries
mailing list