
On Fri, Jun 07, 2013 at 07:08:19AM -0700, David Banas wrote:
op :: Newtypehttp://hackage.haskell.org/packages/archive/newtype/0.2/doc/html/Control-New... n o => (o -> n) -> n -> oSourcehttp://hackage.haskell.org/packages/archive/newtype/0.2/doc/html/src/Control...
This function serves two purposes:
1. Giving you the unpack of a newtype without you needing to remember the name. 2. Showing that the first parameter is *completely ignored* on the value level, meaning the only reason you pass in the constructor is to provide type information. Typeclasses sure are neat.
As point #2, above, emphasizes, the only purpose for the first argument to the function (i.e. - the constructor "(o -> n)") is to specify the type of 'n'. However, being a *newtype*, 'n' can have only one constructor. So, why is it necessary to pass in the constructor to this function, when we're already passing in 'n'?
I am puzzled by this too. What does "op" stand for? I hypothesis "opposite" in the sense of inverse, since as Roman points out "op Constructor :: n -> o" is the inverse of "Constructor :: o -> n". But I admit I do not see how this provides value over "unpack" itself. Tom