[Haskell-cafe] Text and ByteString safety (was Naming scheme for partial functions)
michael at snoyman.com
Thu Feb 20 04:50:21 UTC 2014
I'm not sure about Text, but both the bytestring and vector packages
provide functions like unsafeIndex. The closest equivalent to that in base
would be (!!), which indexes on a list. If you give it an invalid index, it
will throw an exception from pure code (a.k.a., it's a partial function).
That kind of exception can cause problems if you don't expect it, but in
the nearest IO code, you can still catch that exception and let your
program continue operating.
unsafeIndex, on the other hand, performs a memory access which may not just
throw an exception, but could actually cause your program to segfault.
There would be no way to recover from that, unlike partial functions.
I think that's what Antoine is implying, please correct me if I'm mistaken
On Thu, Feb 20, 2014 at 2:12 AM, Lucas Paul <reilithion at gmail.com> wrote:
> I'm still a little new to Haskell. Could someone explain how Text and
> ByteString "push the boundaries of 'unsafe'"?
> On Sat, Feb 15, 2014 at 8:40 AM, Antoine Latter <aslatter at gmail.com>
> > Yeah, that's a good point.Text and Bytestring (and other similar
> > have been pushing the boundaries of 'unsafe' and are in wide use.
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe