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.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to