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@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@gmail.com> wrote:
> Yeah, that's a good point.Text and Bytestring (and other similar packages)
> have been pushing the boundaries of 'unsafe' and are in wide use.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe