[Haskell-beginners] splitAt and negative values
Tom Murphy
amindfv at gmail.com
Fri Sep 7 01:48:46 CEST 2012
One problem you might run into is:
a = 4
b = 5
splitAt (a - b) [1..]
If you don't know what a or b are beforehand, you might be opening up a can
of uncomputable worms.
Tom
On Sep 6, 2012 1:25 PM, "Stayvoid" <stayvoid at gmail.com> wrote:
> Hello,
>
> Could you explain this behaviour?
>
> > splitAt (-1) "Foobar"
> ("","Foobar")
> > splitAt (-100) "Foobar"
> ("","Foobar")
>
> I don't understand why splitAt (-1) "Foobar" doesn't output this:
> ("r", "Fooba")
> or this:
> ("", "Fooba")
>
> How does it work?
>
> Python's list slicing looks similar, but results for negative values
> differ:
> >>> a = "Foobar"
> >>> a[:-1]
> >>> 'Fooba'
>
> Thanks
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120906/6770f82a/attachment.htm>
More information about the Beginners
mailing list