Re: [Haskell-cafe] Why are field selectors functions?

Wouldn't the implementation hiding feature of the *newtype *idiom be broken, if field selectors were not first class functions? For instance, the following code (taken shamelessly from Ch. 10 of *Real World Haskell*): module Parse ( runParser ) where data ParseState = ParseState { string :: String } deriving (Show) newtype Parser a = Parser { runParser :: ParseState -> Either String (a, ParseState) } has the attractive feature of hiding the internal implementation of the *ParseState *and *Parser *types from the user, preventing him from, for instance, pattern matching on either and thus writing code, which may break when we change the implementation. I believe this is only possible, because the *runParser *accessor is exportable as a first class function.
participants (1)
-
David Banas