network icon indicating copy to clipboard operation
network copied to clipboard

getNameInfo: how are Bool arguments and Maybe results related?

Open amigalemming opened this issue 4 years ago • 3 comments

I do not understand the warranties, getNameInfo makes about its results. If an argument is False, does this mean that the corresponding result is always Nothing? Likewise, if an argument is True, does this mean that the corresponding result is always Just?

Related to #416.

amigalemming avatar Mar 18 '21 16:03 amigalemming

I'm not the original author. But the code says that your two assumptions are yes.

kazu-yamamoto avatar Jan 18 '22 01:01 kazu-yamamoto

On Mon, 17 Jan 2022, Kazu Yamamoto wrote:

I'm not the original author. But the code says that your two assumptions are yes.

In this case I propose we have a variant of getNameInfo that expresses these assumptions in types. E.g.

getNameInfo :: (Option f, Option g) => [NameInfoFlag] -> SockAddr -> IO (f HostName, g ServiceName)

class Option f where instance Option Identity where instance Option Ignore where

data Ignore a = Ignore -- isomorphic to Proxy

amigalemming avatar Jan 18 '22 09:01 amigalemming

I agree with you. We should define variants, for instance, getAddrInformation and getNameInformation which are clean for error codes.

kazu-yamamoto avatar Jan 18 '22 23:01 kazu-yamamoto