[Haskell-cafe] Is "take" behaving correctly?

PR Stanley prstanley at ntlworld.com
Tue Sep 11 19:46:19 EDT 2007


Let me get this right, are you saying it's unsafe when it returns an error?
Paul

At 00:40 12/09/2007, you wrote:
>byorgey:
> >    On 9/11/07, PR Stanley <[1]prstanley at ntlworld.com> wrote:
> >
> >      Hi
> >      take 1000 [1..3] still yields [1,2,3]
> >      I thought it was supposed to return an error.
> >      Any ideas?
> >      Thanks, Paul
> >
> >    If for some reason you want a version that does return an error in that
> >    situation, you could do something like the following:
> >
> >    take' n _ | (n <= 0) = []
> >    take' n [] | (n > 0) = error "take': list too short"
> >               | otherwise = []
> >    take' n (x:xs) = x : take' (n-1) xs
>
>And we'd call it unsafeTake, just like unsafeFromJust and unsafeTail :-)
>
>-- Don
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070912/a176777c/attachment.htm


More information about the Haskell-Cafe mailing list