4 ms·
> prelude has unsafe functions (eg. head), `head` is not unsafe, it is a partial function. An unsafe function can lead to u.b.; the behavior of `head` on an em
by Blikkentrekker 6y ago
> prelude has unsafe functions (eg. head),
`head` is not unsafe, it is a partial function. An unsafe function can lead to u.b.; the behavior of `head` on an empty list is very much defined. Haskell is not a total language.
- jokethrowaway 6y agoThanks for the correction, changed to exception-throwing - that's the behaviour I don't like
- Quekid5 6y agoI think it's worth pointing out that your values[0] may not align with Haskell's values. That's absolutely fine, but it doesn't mean that Haskell is "bad" in some objective sense. AFAICT, most of your 'complaints' would apply equally to, say, Java or C#. [0] I can't recall which exact presentation it was, but Bryan Cantrill had a brilliant segment on this in one of them. Perhaps others around here can remember?
- girvo 6y agoThey didn’t argue that it was “bad in some objective sense”, they pointed out a feature in Haskell that they specifically don’t like. Unless you consider Haskell to be a perfect language, discarding an opinion that was labeled as exactly that seems silly to me. Especially with such a broad strokes “love it or leave it” reply... Those complaints apply to those languages too, yes. What’s your point here?
- Quekid5 6y agoI may have overreacted to the title of the blog post and carried that over to the post I replied to :). That's my bad.
- codesections 6y ago> I can't recall which exact presentation it was, but Bryan Cantrill had a brilliant segment on this in one of them. Perhaps others around here can remember? I think that's his discussion of language values in "Rust and Other Interesting Things" at Scale By The Bay 2018. https://www.youtube.com/watch?v=2wZ1pCpJUIM https://www.youtube.com/watch?v=2wZ1pCpJUIM [edit: This talk is also titled "Platform values, Rust, and implications for systems software". I'm not sure which title is preferred.]
- Quekid5 6y agoYup, sounds about right. That was an excellent insight from him.
- EE84M3i 6y agoAs an aside -- Rust's definition of "unsafe" (e.g. "can lead to u.b.") is not the only definition of unsafe one can use for a programming language, which can have different safety guarantees. As a motivating example, in many languages converting a reference to an integer containing a memory address is unsafe (e.g. Java[1]/golang[2]/C#[3]/Haskell[4]), but this is considered safe in Rust.[5] All these languages literally use the word "unsafe" for it. [1]: See sun.misc.Unsafe, which indirectly provides this https://stackoverflow.com/a/7060500/315936 https://stackoverflow.com/a/7060500/315936 [2]: https://golang.org/pkg/unsafe/#Pointer https://golang.org/pkg/unsafe/#Pointer [3]: pointer types are only allowed with the unsafe keyword, see: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/unsafe-code-pointers/pointer-types https://docs.microsoft.com/en-us/dotnet/csharp/programming-g... [4]: I believe this requires unsafeCoerce https://stackoverflow.com/a/18563789/315936 https://stackoverflow.com/a/18563789/315936 [5]: https://doc.rust-lang.org/reference/unsafety.html https://doc.rust-lang.org/reference/unsafety.html
- Blikkentrekker 6y agoIt is Haskell's definition, however. All functions that have `unsafe` as part of their name have it because they can lead to u.b. with improper use.
- EE84M3i 6y agoIs it? The definition I see in the GHC docs seems to be broader than that: https://downloads.haskell.org/ghc/latest/docs/html/users_guide/safe_haskell.html#safe-language https://downloads.haskell.org/ghc/latest/docs/html/users_gui... Regardless, I agree the function under discussion though, "head", is not "unsafe" in either sense. That's why I said "as an aside".
- ImprobableTruth 6y agoI think in all these cases unsafe actually means 'leads to UB'. Converting a pointer to an integer address is problematic if you have a garbage collector due to compacting. Technically it's still the dereferencing that actually causes the UB, but I don't think this is too much of a leap. C# marking all pointers unsafe also makes sense in the same way, because "passing pointers between methods can cause undefined behavior."