Skip to content

socketPort does not handle Unix sockets #319

Description

@eborden

socketPort is a partial function. It only supports AF_INET and AF_INET6. Its type signature is not really indicative of this. IO informs that this function could throw from an exception, but partiality should be communicated with Maybe.

Originally reported by @RyanGlScott here #318 (comment)

Activity

  1. kazu-yamamoto commented on May 2, 2018

    @kazu-yamamoto
    Collaborator

    I'm not sure which is better:

    1. Keep this code and update the documentation
    2. Change the signature to Socket -> IO (Maybe PortNumber)
  2. eborden commented on May 2, 2018

    @eborden
    CollaboratorAuthor

    @kazu-yamamoto It is a tough call. If we don't want to change the type signature then we must update the documentation.

    Option 1

    Pro

    • This does not cause API breakage.
    • It doesn't require pointer indirection introduced by Maybe

    Con

    • We continue to have a partial function.
    • Documentation can easily get out of sync with reality.

    Option 2

    Pro

    • It communicates partiality within the type.
    • It leaves how to handle that partiality up to the consumer.
    • It doesn't mix true exceptions with non exceptional failure.

    Con

    • It causes API breakage.
    • It requires pointer indirection, so will be less efficient.
  3. kazu-yamamoto commented on May 7, 2018

    @kazu-yamamoto
    Collaborator

    I would suggest to create a new API, for instance, socketPortSafe :: Socket -> IO (Maybe PortNumber) and update the doc of socketPort.

  4. kazu-yamamoto commented on May 25, 2018

    @kazu-yamamoto
    Collaborator

    socketPortSafe is implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions