Why Handle and not any type for network in Haskell?

haskell, networking, types

Solution

The data going over the network is just a stream of bytes. You can assign meaning to that stream of bytes at either endpoint, but on the network it has no meaning. As far as I know, this is true of every language, some just choose to abstract that away in their standard library.

You can encode/decode the data you're sending with packages like binary or cereal (using the `encode` and `decode` functions). Both come with instances of their serialization classes (`Binary` and `Serialize`, respectively) for many of the standard types like `Int`, `Double`, `Bool`, and `[]`.

Problem

The type of sent and received data over network is String, or Bytestring. We can't send any other types, like `Int`, or `[Bool]` for example, because everything passed through a `Handle`. I know we can parse it, even using `read`, but I think it's not beautiful, nor reliable, and effective as well. Why was this choice made? Is it because it's technically "impossible" otherwise, or because `Network` is just a binding to a C library, because of delays, or because of something else?

Original source