[Haskell-beginners] hiding members of a data, separate accessors instead

Daniel Trstenjak daniel.trstenjak at gmail.com
Sun Mar 24 19:25:34 CET 2013

Hi Emmanuel,

> So I'm not even sure how he achieved that the members are not visible,
> the data are exported with (..) as is usually done...

I don't think that the members are hidden, see Gabriels post, you just
seem to be misinterpreting the compiler warnings.

> Although pattern matching on a data with 6 fields
> is always going to be a pain and decreasing the chances for modifying
> the data type without breaking compatibility.

You can use the record syntax also for pattern matching:

someFunc :: Response -> (StatusCode, ByteString)
someFunc Response {pStatusCode = code, pStatusMsg = msg} = (statusCode, msg)

> These "members" are also causing me problems in other situations, for
> instance I have some cases when I use a data type only a few times and with
> -Wall the compiler tells me I don't use the accessor; in fact I read that
> value from the data, but through pattern matching/deconstruction only, not
> through that particular function. I'm thinking to try to hide the warning
> as I think my code is correct.

A data type defined with record syntax is probably more likely to be
changed at any position, so it's more secure not to pattern match by the
position of the fields.


More information about the Beginners mailing list