News for hackers. Stuff that matters.
Re:Measuring GC latencies in Haskell, OCaml, Racket by coldcode on Monday December 05, 2016 @08:08AM (#13105085)
I don't know Haskell but it sure has some odd syntax:

    type Chan = Map.Map Int ByteString.ByteString
is odd looking. Why the duplication?
Re:Measuring GC latencies in Haskell, OCaml, Racket by uryga on Monday December 05, 2016 @09:27AM (#13105505)
Haskell namespaces are a bit annoying.

let's look at the stdlib `replicate` function. `replicate 5 'x'` gets you `['x', 'x', 'x', 'x', 'x']`. But that's a standard haskell linked list, and there's other list-y things, like ByteString. So there's bytestring module has it's own replicate function which returns a ByteString (like an array afaik) instead of a list.

Now, a bare `import bytestring` just dumps all of the module - its datatypes, its functions - into the global namespace, like a Python `from bytestring import *`, so the two replicate functions are gonna clash. There's a solution - we do `import qualified bytestring`. it behaves like a normal Python `import bytestring`, which means that we have to type `bytestring.replicate` to get that function from earlier. all of the stuff inside the bytestring module is hidden away inside this namespace.

Now, the trouble is, EVERYTHING is hidden away. So, say I want to refer to the actual ByteString datatype, say to write a type signature like: ``` length :: Bytestring a -> Int ``` Now, because of the namespace qualification I did, I actually have to write the verbose ``` length :: bytestring.ByteString a -> Int ``` So that's like saying "bytestring-module.ByteString-datatype" every time you want use a ByteString. that's what the author does, hence the weird duplication you noticed comes from.

The usual solution is: ``` import qualified Data.ByteString as B -- the functions import Data.ByteString (ByteString) -- the datatype ```

which roughly translates to Python as: ``` import bytestring as B from bytestring import ByteString # the ByteString class ```

so now, I can use `B.replicate`, and `ByteString`, which is what I want! Great! But the importing is verbose and, as I said, kinda annoying.

Re:Measuring GC latencies in Haskell, OCaml, Racket by evincarofautumn on Monday December 05, 2016 @08:23AM (#13105139)
They used qualified imports:

    import qualified Data.ByteString as ByteString
    import qualified Data.Map.Strict as Map
So everything from “Data.ByteString” has to be prefixed with “ByteString.”

In real-world code, depending on conventions, you’d probably add unqualified imports for the type names to avoid the needless duplication:

    import Data.ByteString (ByteString)
    import Data.Map.Strict (Map)
    import qualified Data.ByteString as ByteString
    import qualified Data.Map.Strict as Map

    type Chan = Map Int ByteString

    pushMsg =
      …
        let inserted = Map.insert …
Re:Measuring GC latencies in Haskell, OCaml, Racket by buckie on Monday December 05, 2016 @09:24AM (#13105481)
Also, `ByteString` as the qualified name is a bit unusual but it probably is helpful for clarifying what's going on for people unfamiliar with Haskell. I'm more used to seeing:

    import Data.ByteString (ByteString)
    import qualified Data.ByteString as BS
    import qualified Data.ByesString.Lazy as BSL
    import qualified Data.ByteString.Char8 as BSC
Re:Measuring GC latencies in Haskell, OCaml, Racket by marcosdumay on Monday December 05, 2016 @08:12AM (#13105095)
That's what you get by importing qualified and being too verbose.

This same can be written as:

  type Chan = Map Int ByteString
People do prefer importing Map and ByteString qualified, so their functions will have a prefix of their choice. But very few people import ByteString as "ByteString", most use something shorter.
Re:Measuring GC latencies in Haskell, OCaml, Racket by moomin on Monday December 05, 2016 @09:16AM (#13105433)
Gotta say, I'm Team Qualified Import. Use it all the time in my Clojure code. I want to know where things come from.
Re:Measuring GC latencies in Haskell, OCaml, Racket by marcosdumay on Monday December 05, 2016 @10:43AM (#13106092)
On Haskell you don't even get much choice. The community is so biased towards qualified importing that most modules clash, and you'd need some incredible stretching to use them unqualified.

As most things in Haskell, it tends to work greatly. The usual problems go away due to some combination of Haskell's features and the main problems are things you wouldn't think about.

Re:Measuring GC latencies in Haskell, OCaml, Racket by hood_syntax on Monday December 05, 2016 @10:11AM (#13105767)
Totally reasonable, but most people would use BS instead of ByteString as the qualified name.